如何创建可移动UItextfield,使其停留在屏幕底部,当键盘出现时,它会移动到iphone应用程序中键盘的顶部?如何在Xcode4.2中做到这一点?就像whatsapp和Skype聊天一样。我想使用将字符串输入到表中。
发布于 2012-03-24 10:13:10
您应该将viewController注册为键盘通知的侦听器。当键盘出现时,会触发一个带有用户字典的通知。字典将包含有用的信息,如键盘相对于屏幕的位置,用于将textFields帧动画显示到新位置。查看文档:
http://developer.apple.com/library/ios/#DOCUMENTATION/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html
具体地说,您需要的通知是:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];在大多数情况下,您需要将它们添加到viewDidLoad中。以后在viewDidUnload中使用done.Such时,别忘了取消注册通知(removeObserver:)。
发布于 2012-03-24 10:47:45
你可以像休伯特提到的那样使用通知,或者你可以不断地检查UITextField是否是第一响应者。如果它是第一个响应者,这意味着文本字段被选中,并且键盘将影响该字段。
-(void)viewDidLoad {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(checkTextField) userInfo:nil repeats:YES];
}
-(void)checkTextField {
if (textField isFirstResponder) {
//the text field has been tapped and the keyboard will come up, so animate the text field moving up here
} else {
//the text field is not selected, so it should be in its original position
}
}https://stackoverflow.com/questions/9847585
复制相似问题