一切都运行良好,直到iOS 8。 但是当用户点击文本字段控件直接来自UIKeyboardWillHideNotification通知时 登录控制台 - 无法找到支持键盘iPhone-PortraitTruffle-NumberPad类型4的键盘;使用675849259_PortraitTruffle_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];
}
`
答案 0 :(得分:12)
这可能与模拟器设置有关,请参阅菜单“硬件>键盘>连接键盘硬件”。如果此选项为开启,您将获得UIKeyboardWillHideNotification
,但永远不会UIKeyboardWillShowNotification
。