用户可以在ipad中使用键盘来编写文本。
他能够将该文本从一个地方拖到另一个地方。 有可能吗?
请帮帮我。
提前谢谢你!
答案 0 :(得分:1)
如果要移动整个文本字段,则可以使用以下代码:
请注意,您必须在标题
中声明类似userIsTouching的布尔值- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// Check if the user's touch is within the textfield
CGPoint touch = [[touches anyObject] locationInView:self.view];
if (CGRectContainsPoint(textField.frame, touch)) {
userIsTouching = YES;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (userIsTouching) {
textField.center = [[touches anyObject] locationInView:self.view];
}
}
// Obviously, you then have to set the userIsTouching variable to NO when the user releases the touch
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
userIsTouching = NO;
}
这样的事情应该这样做。