使用键盘下的UITextFields向上移动UIView
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用键盘下的UITextFields向上移动UIView相关的知识,希望对你有一定的参考价值。
Add this code to the controllerSet controller as the delegate of the all the UITextField s in the UIView
- (void) animateTextField: (UITextField*) textField up: (BOOL) up{ int txtPosition = (textField.frame.origin.y - 140); const int movementDistance = (txtPosition < 0 ? 0 : txtPosition); // tweak as needed const float movementDuration = 0.3f; // 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]; } - (void)textFieldDidBeginEditing:(UITextField *)textField{ [self animateTextField: textField up: YES]; } - (void)textFieldDidEndEditing:(UITextField *)textField{ [self animateTextField: textField up: NO]; } - (BOOL)textFieldShouldReturn:(UITextField *)theTextField { [theTextField resignFirstResponder]; return YES; }
以上是关于使用键盘下的UITextFields向上移动UIView的主要内容,如果未能解决你的问题,请参考以下文章
无法滚动包含 UITextFields 的 UITableViewCells
使用键盘时使用 UIScrollView 滑动并向上移动视图
当使用 Swift 出现键盘时如何向上移动 UIViewController 的内容