【发布时间】:2016-12-29 23:10:23
【问题描述】:
当textView 显示或隐藏键盘时,我正在使用下面的代码向上或向下移动屏幕,这样我可以在聚焦时看到最后一个字段。
- (void)textViewDidBeginEditing:(UITextView *)textField
{
[self animateTextView: textField up: YES];
}
- (void)textViewDidEndEditing:(UITextView *)textField
{
[self animateTextView: textField up: NO];
}
- (void) animateTextView: (UITextView*) textField up: (BOOL) up
{
const int movementDistance = 130; // tweak as needed
const float movementDuration = 0.2f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
但问题是navBar在屏幕向上移动时也会移动,有没有办法移动除了navBar之外的所有东西,或者在使用[self animateTextView: textField up: YES];后将navBar保持在它的位置?
【问题讨论】:
-
为什么?你为什么要这样设计你的视图?为什么不使用
UINavigationController?你为什么使用beginAnimations:API?这是什么,iOS / iphoneos 3?
标签: ios objective-c navbar