How to scroll view up on keyboard appear

you should use this code to scroll the view on keyboard appear

Basically whenever you want to enter some text on the textfield a default keyboard appear over the view sometimes what happen whenever the textfield present at the bottom of screen so at that type you will not be able to visible it.

Here is the way to make it visible.

first of all you need to inherit the UITextFieldDelegate protocol in your .h file
and after that in your code make the textfield delegate to its file owner
or use this code

textField.delegate=self;

and override this methodss


-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    NSTimeInterval animationDuration = 0.300000011920929;
    CGRect frame = self.view.frame;
    y=textField.frame.origin.y;
    frame.origin.y =-y;
    frame.size.height +=y;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
    y=0;
    return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    NSTimeInterval animationDuration = 0.300000011920929;
    CGRect frame = self.view.frame;
    frame.origin.y += y;
    frame.size.height-=y;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    if(textField.tag==5)
        [self sendKeyboardAway:textField];
    [UIView commitAnimations];      
  
    return YES;
}

Comments

Popular posts from this blog

How to set background color of navigation bar in iPhone

Checking Device Info in ios

Some Interactive tips to take input form GUI Dialogs