gpt4 book ai didi

objective-c - UIKeyboardWillShowNotification 不调用,只有 UIKeyboardWillHideNotification 在 iOS 9 中调用

转载 作者:太空狗 更新时间:2023-10-30 03:57:47 25 4
gpt4 key购买 nike

在 iOS 8 之前一切正常。但是,当用户点击文本字段控件时,会直接出现在 UIKeyboardWillHideNotification 通知中登录控制台-找不到支持type 4 for keyboard iPhone-PortraitTruffle-NumberPad的keyplane;使用 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];

}

`

最佳答案

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

关于objective-c - UIKeyboardWillShowNotification 不调用,只有 UIKeyboardWillHideNotification 在 iOS 9 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32817089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com