IOS键盘出现时视图上移

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

]]>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注