I have a simple UITextField
, that when someone goes to edit it, and the keyboard pops up, the view shifts up so that the user can see what they are entering. However, when I close the keyboard, the view is not returning to the original position! I am using a CGPoint
property to capture its original position on viewDidLoad
and then try and set it back to that when the keyboard is closed.
Code:
- (void)viewDidLoad {
[super viewDidLoad];
// Set the original center point for shifting the view
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
self.originalCenter = self.view.center;
}
- (void)doneWithNumberPad {
[locationRadius resignFirstResponder];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.center = self.originalCenter;
[UIView commitAnimations];
}
- (void)keyboardDidShow:(NSNotification *)note
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
self.view.center = CGPointMake(self.originalCenter.x, 150);
[UIView commitAnimations];
}