我有一个UIView
with a UITextField
放置在屏幕底部,当键盘出现时它将向上移动。
在 iOS 8 之前我一直遵循以下方法,似乎效果很好。
// When Keyboard appears
- (void)keyboardWillShow:(NSNotification *)notification {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
[UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey]integerValue]];
[UIView setAnimationBeginsFromCurrentState:YES];
// Frame Update
CGRect frame = self.bottomView.frame;
frame.origin.y = self.view.frame.size.height - 266.0f;
self.bottomView.frame = frame;
[UIView commitAnimations];
}
// When keyboard disappears
- (void) keyboardHides : (NSNotification *) notification {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
[UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]];
[UIView setAnimationBeginsFromCurrentState:YES];
// Frame update
CGRect frame = self.bottomView.frame;
frame.origin.y = self.view.frame.size.height - self.bottomView.frame.size.height;
self.bottomView.frame = frame;
[UIView commitAnimations];
}
但上面的代码似乎不起作用iOS 8
因为键盘挡住了它后面的 UIView。
经过一番研究后,我发现了一个几乎相似回答。但这里整个UIView
被推高了,而我想要实现的只是移动bottom UIView
.
获取 TPKeyboardAvoidingScrollView 从https://github.com/michaeltyson/TPKeyboardAvoiding
按如下方式使用它。
将 TPKeyboardAvoidingScrollView.m 和 TPKeyboardAvoidingScrollView.h 源文件放入您的项目中,将 UIScrollView 弹出到视图控制器的 xib 中,将滚动视图的类设置为 TPKeyboardAvoidingScrollView,并将所有控件放入该滚动视图中。您还可以通过编程方式创建它,而不使用 xib - 只需使用 TPKeyboardAvoidingScrollView 作为顶级视图。
要禁用自动“下一步”按钮功能,请将 UITextField 的返回键类型更改为除 UIReturnKeyDefault 之外的任何类型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)