【发布时间】: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