【发布时间】:2014-10-08 10:52:58
【问题描述】:
我有一个UIView 和一个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。
经过一番研究,我找到了almost-similar 的答案。但是这里整个UIView 都被推高了,我想要实现的只是移动bottom UIView。
【问题讨论】:
-
你为什么不把所有的东西都放在
UIScrollView上,当键盘出现时向下滚动? -
我建议您放弃动画解决方案并在
UITextField上使用inputAccessoryView。据我所知,这就是你想要做的事情。 -
@Roma-MT 不想那样做 :)
-
@Sreejith 然后不要! ;-)
标签: ios objective-c iphone uiview ios8