【发布时间】:2018-02-05 20:09:00
【问题描述】:
在 iOS 11 beta 7 上测试我的应用 - 如果我的 UIViewController.
代码如下所示(从 iOS7 开始工作):
- (void)handleNotification:(NSNotification*)notification {
if (notification.name == UIKeyboardWillShowNotification) {
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
nextButtonALBottomDistance.constant = keyboardSize.height + initialPhoneBottomDistance;
codeBottomViewALBottomDistance.constant = keyboardSize.height + initialCodeBottomDistance;
double animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:animationDuration animations:^{
[self.view layoutIfNeeded];
}];
}
else if (notification.name == UIKeyboardWillHideNotification) {
nextButtonALBottomDistance.constant = initialPhoneBottomDistance;
codeBottomViewALBottomDistance.constant = initialCodeBottomDistance;
double animationDuration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView animateWithDuration:animationDuration animations:^{
[self.view layoutIfNeeded];
}];
}
}
足够有趣 - 当我按下主页按钮(最小化应用程序)并重新打开它(不杀死它)时 - 布局是固定的。
这似乎是一个 iOS 11 测试版错误,但到目前为止我找不到任何参考。
很高兴知道其他人是否有此问题。
【问题讨论】:
-
用
UIKeyboardframeenduserinfokey替换UIKeyboardFrameBeginUserInfoKey -
似乎有效!非常感谢@AdityaSrivastava!
-
很高兴为您提供帮助
-
为什么这个通知将键盘高度设为 0.0 这就是我获取键盘大小的方式...
let info1: NSDictionary = (notification as NSNotification).userInfo! as NSDictionary let value: NSValue = info1.value(forKey: UIKeyboardFrameBeginUserInfoKey) as! NSValue -
但它适用于
UIKeyboardframeenduserinfokey@AdityaSrivastava 任何想法?
标签: ios objective-c keyboard ios11