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

2016-09-08  本文已影响11人  Locaus_Joe

- (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];

}

上一篇下一篇

猜你喜欢

热点阅读