在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测试版的一个bug,但我目前还没有找到任何相关参考。
如果其他人也遇到了这个问题,我很乐意知道。
UIKeyboardFrameBeginUserInfoKey
替换为UIKeyboardframeenduserinfokey
。 - Aditya Srivastavalet info1: NSDictionary = (notification as NSNotification).userInfo! as NSDictionary let value: NSValue = info1.value(forKey: UIKeyboardFrameBeginUserInfoKey) as! NSValue
- Suryakant SharmaUIKeyboardframeenduserinfokey
吗?@AdityaSrivastava 有什么想法吗? - Suryakant Sharma