【发布时间】:2014-09-17 18:05:59
【问题描述】:
我让我们尝试在键盘上方显示自己,并且一旦打开键盘就不应移动。
我可以调整它的显示位置,但使用 quicktype 键盘我无法确定键盘的高度,除非我知道 quicktype 是打开还是关闭。有什么方法可以确定吗?
【问题讨论】:
-
在链接中看看我的解决方案:stackoverflow.com/questions/26213681/…
我让我们尝试在键盘上方显示自己,并且一旦打开键盘就不应移动。
我可以调整它的显示位置,但使用 quicktype 键盘我无法确定键盘的高度,除非我知道 quicktype 是打开还是关闭。有什么方法可以确定吗?
【问题讨论】:
您应该使用keyboardWillShow: 通知来调整其他视图框架。
通知会发布到keyboardWillShow:不仅在becomeFirstResponder 上针对文本视图/字段,而且在用户显示/隐藏快速类型键盘时也会发布。
一旦keyboardWillShow: 通知被发布,键盘的框架就可以被通知对象中的UIKeyboardFrameEndUserInfoKey 捕获。
textView 基于键盘调整其框架的示例:
- (void)keyboardWillShow:(NSNotification *)notification
{
CGRect keyboardRect = [[[notification userInfo] valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve curve = [[[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
[UIView animateWithDuration:duration animations:^{
[UIView setAnimationCurve:curve];
self.textViewVisualEffectView.frame = CGRectMake(self.textViewVisualEffectView.origin.x, self.view.height - keyboardRect.size.height - self.textViewVisualEffectView.height, self.textViewVisualEffectView.width, self.textViewVisualEffectView.height);
} completion:^(BOOL finished) {
}];
}
【讨论】: