【问题标题】:UIKeyboardWillShowNotification not calling and only UIKeyboardWillHideNotification calling in iOS 9UIKeyboardWillShowNotification 没有调用,只有 UIKeyboardWillHideNotification 在 iOS 9 中调用
【发布时间】:2015-09-28 06:44:54
【问题描述】:

在 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];

}

`

【问题讨论】:

  • 模拟器的问题
  • 我也有类似的问题。你的代码只能在真实设备上运行吗?

标签: objective-c iphone notifications uitextfield ios9


【解决方案1】:

这可能与模拟器设置有关,请参阅菜单“硬件 > 键盘 > 连接键盘硬件”。如果此选项开启,您将获得UIKeyboardWillHideNotification,但永远不会获得UIKeyboardWillShowNotification

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多