Return to Snippet

Revision: 50425
at August 20, 2011 22:37 by yasirmturk


Initial Code
- (void) animateTextField: (UITextField*) textField up: (BOOL) up{
	int txtPosition = (textField.frame.origin.y - 140);
    const int movementDistance = (txtPosition < 0 ? 0 : txtPosition); // 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];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [self animateTextField: textField up: YES];
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    [self animateTextField: textField up: NO];
}

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {	
	[theTextField resignFirstResponder];
	return YES;
}

Initial URL
http://yasirmturk.com/blog

Initial Description
Add this code to the controller
Set controller as the delegate of the all the UITextField s in the UIView

Initial Title
Move up the UIView with UITextField s under the keyboard

Initial Tags
iphone

Initial Language
Objective C