UIKeyboardWillShowNotification 没有调用,只有 UIKeyboardWillHideNotification 调用 iOS 9
UIKeyboardWillShowNotification not calling and only UIKeyboardWillHideNotification calling in iOS 9
直到 iOS 8 点之前一切正常。
但是,当用户点击文本字段控件时,会直接出现在 UIKeyboardWillHideNotification 通知中
登录控制台 - 找不到支持键盘类型 4 的键盘 iPhone-PortraitTruffle-NumberPad;使用 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];
}
`
这可能与模拟器设置有关,请参阅菜单 "Hardware > Keyboard > Connect Keyboard Hardware"。如果此选项打开,您将获得 UIKeyboardWillHideNotification
,但永远不会 UIKeyboardWillShowNotification
.
直到 iOS 8 点之前一切正常。 但是,当用户点击文本字段控件时,会直接出现在 UIKeyboardWillHideNotification 通知中 登录控制台 - 找不到支持键盘类型 4 的键盘 iPhone-PortraitTruffle-NumberPad;使用 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];
}
`
这可能与模拟器设置有关,请参阅菜单 "Hardware > Keyboard > Connect Keyboard Hardware"。如果此选项打开,您将获得 UIKeyboardWillHideNotification
,但永远不会 UIKeyboardWillShowNotification
.