UIKeyboardWillShowNotification且仅

UIKeyboardWillShowNotification且仅

本文介绍了在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 notificationLog 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:14