到iOS8为止一切都很好。
但当用户点击文本字段控件时,uikeyboardwillhidenotification通知会直接出现
登录控制台-找不到支持键盘输入4的键盘iphone肖像松露数字pad;使用675849259_肖像松露_iphone-simple-pad_default
这是密码--
`
In view did load
- (void)viewDidLoad {
[super viewDidLoad];
self.txtMobNumber.delegate = self;
self.txtMobNumber.keyboardType = UIKeyboardTypeNumberPad;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:@"UIKeyboardWillShowNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:@"UIKeyboardWillHideNotification" object:nil];
}
notification callback
- (void)keyboardWillShow:(NSNotification *)notification
{
// Save the height of keyboard and animation duration
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardRect = [userInfo[@"UIKeyboardBoundsUserInfoKey"] CGRectValue];
[UIView beginAnimations:@"moveKeyboard" context:nil];
float height = keyboardRect.size.height-60;
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - height, self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
// [self setNeedsUpdateConstraints];
}
// Reset the desired height
- (void)keyboardWillHide:(NSNotification *)notification
{
// Reset the desired height (keep the duration)
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardRect = [userInfo[@"UIKeyboardBoundsUserInfoKey"] CGRectValue];
[UIView beginAnimations:@"moveKeyboard" context:nil];
float height = keyboardRect.size.height-60;
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + height, self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
`
最佳答案
这可能与模拟器设置有关,请参阅菜单“硬件>键盘>连接键盘硬件”。如果此选项处于启用状态,您将得到UIKeyboardWillHideNotification
,但永远不会得到UIKeyboardWillShowNotification
。