UIKeyboardWillShowNotification未调用且仅在iOS 9中调用UIKeyboardWillHideNotification

Hus*_*ala 4 iphone notifications objective-c uitextfield ios9

一切都运行良好,直到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];

}

`
Run Code Online (Sandbox Code Playgroud)

Fra*_*sch 12

这可能与模拟器设置有关,请参见菜单"硬件>键盘>连接键盘硬件".如果此选项为ON,您将获得UIKeyboardWillHideNotification,但绝不会UIKeyboardWillShowNotification.