iOS2012. 9. 28. 09:59

  1. - (void) animateTextField: (UITextField*) textField up: (BOOL) up{
  2. int txtPosition = (textField.frame.origin.y - 140);
  3. const int movementDistance = (txtPosition < 0 ? 0 : txtPosition); // tweak as needed
  4. const float movementDuration = 0.3f; // tweak as needed
  5.  
  6. int movement = (up ? -movementDistance : movementDistance);
  7.  
  8. [UIView beginAnimations: @"anim" context: nil];
  9. [UIView setAnimationBeginsFromCurrentState: YES];
  10. [UIView setAnimationDuration: movementDuration];
  11. self.view.frame = CGRectOffset(self.view.frame, 0, movement);
  12. [UIView commitAnimations];
  13. }
  14.  
  15. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  16. [self animateTextField: textField up: YES];
  17. }
  18.  
  19. - (void)textFieldDidEndEditing:(UITextField *)textField{
  20. [self animateTextField: textField up: NO];
  21. }
  22.  
  23. - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  24. [theTextField resignFirstResponder];
  25. return YES;
  26. }

Posted by 다오나무