How to animate textField on the top of Keyboard while Editing...
#pragma – mark Textfield Delegate Methods..
-(void)textFieldDidBeginEditing:(UITextField *)textField {
[self animateTextField:textField up:YES withOffset:textField.frame.origin.y / 2];
}
-(void)textFieldDidEndEditing:(UITextField *)textField {
[self animateTextField:textField up:NO withOffset:textField.frame.origin.y / 2];
}
#pragma – mark Textfield Animation Method
-(void)animateTextField:(UITextField*)textField up:(BOOL)up withOffset:(CGFloat)offset
{
const int movementDistance = -offset;
const float movementDuration = 0.4f;
int movement = (up ? movementDistance : -movementDistance);
[UIView beginAnimations: @"animateTextField" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
No comments:
Post a Comment