美文网首页
TextField 编辑视图上移,编辑完成视图恢复

TextField 编辑视图上移,编辑完成视图恢复

作者: Locaus_Joe | 来源:发表于2016-09-08 15:26 被阅读11次

- (void)textFieldDidBeginEditing:(UITextField *)textField

{

[self animateTextField: textField up: YES];

}

- (void)textFieldDidEndEditing:(UITextField *)textField

{

[self animateTextField: textField up: NO];

}

- (void) animateTextField: (UITextField*) textField up: (BOOL) up

{

const int movementDistance = 80; // 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];

}

相关文章

网友评论

      本文标题:TextField 编辑视图上移,编辑完成视图恢复

      本文链接:https://www.haomeiwen.com/subject/yyisettx.html