我让我们尝试在键盘上方显示自己,并且一旦键盘打开就不应该移动.
我可以调整它显示的位置但是使用快速键盘我无法确定键盘的高度,除非我知道快捷键是打开还是关闭.有什么办法可以确定吗?
小智 8
您应该使用keyboardWillShow:notification来调整其他视图框架.
通知将发布到keyboardWillShow:不仅适用于becomeFirstRespondertextView/Field,还适用于用户显示/隐藏快速类型键盘的情况.
一旦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) {
}];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3634 次 |
| 最近记录: |