在iOS 9中不调用UIKeyboardWillShowNotification且仅调用UIKeyboardWillHideNotification [英] UIKeyboardWillShowNotification not calling and only UIKeyboardWillHideNotification calling in iOS 9

查看:289
本文介绍了在iOS 9中不调用UIKeyboardWillShowNotification且仅调用UIKeyboardWillHideNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 8之前一切正常. 但是,当用户点击文本字段控件时,它会直接出现在UIKeyboardWillHideNotification通知中 登录控制台-找不到支持键盘iPhone-PortraitTruffle-NumberPad的类型4的键盘;使用675849259_PortraitTruffle_iPhone-Simple-Pad_Default

All is working good till iOS 8. But when user tap on text field control comes directly in UIKeyboardWillHideNotification notification Log in console -Can't find keyplane that supports type 4 for keyboard iPhone-PortraitTruffle-NumberPad; using 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];

}

`

推荐答案

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

This can be related to simulator setup, see menu "Hardware > Keyboard > Connect Keyboard Hardware". If this option is ON, you will get UIKeyboardWillHideNotification, but never UIKeyboardWillShowNotification.

这篇关于在iOS 9中不调用UIKeyboardWillShowNotification且仅调用UIKeyboardWillHideNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆