iphone adjustable UITextField when keyboard popup

By | June 15, 2011

In iphone programming there is no direct method to move the UITextField above the keyboard. Instead we do some adjustment.

Iphone keyboard occupies the bottom 216 pixels on the screen so the UITextField placed at the bottom will not be visible. Try this method

The first function will move the UITextField to the position we specify.Here i want to move it to 100(y coordinate)

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    textView.center = CGPointMake(textView.center.x, 100);
    [UIView commitAnimations];
}

When the TextView editing is completed,it will move to the original position(274)

- (void)textViewDidEndEditing:(UITextView *)textView
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    textView.center = CGPointMake(textView.center.x, 274);
    [UIView commitAnimations];
}

The important point is
You will need to make the view controller the delegate (in Interface Builder) for every UITextField you want to animate.


Leave a Reply

Your email address will not be published. Required fields are marked *