【问题标题】:Adjusting view frame for iOS hardware keyboard调整 iOS 硬件键盘的视图框架
【发布时间】:2015-03-13 04:11:33
【问题描述】:
【问题讨论】:
标签:
ios
objective-c
keyboard
【解决方案2】:
遇到了同样的问题。
看起来 iOS 键盘已完全实例化,并且在连接硬件键盘时只是移出视图部分。因此键盘的大小是合适的。只是没有完全显示出来。
在检查了通知之后,我自己计算了可见的键盘高度来解决它。
在我的示例中,我正在收听 UIKeyboardWillShowNotification、UIKeyboardWillChangeFrameNotification 和 UIKeyboardWillHideNotification。
-(void)keyboardMessage:(NSNotification*)notification {
NSDictionary *userInfo = notification.userInfo;
CGFloat duration = [userInfo[@"UIKeyboardAnimationDurationUserInfoKey"] floatValue];
NSValue *value = userInfo[@"UIKeyboardFrameEndUserInfoKey"];
CGRect frame = [value CGRectValue];
[UIView animateWithDuration:duration animations:^{
self.lowerContraint.constant = self.view.frame.size.height - frame.origin.y;;
[self.view needsUpdateConstraints];
[self.view layoutIfNeeded];
}];
}