How to scroll view up when keyboard appears?

后端 未结 7 1387
小蘑菇
小蘑菇 2021-01-31 02:54

I know that this question has been asked over and over again, but nothing seems to be working for me. Most of the solutions around are pretty out of date, and the rest are incre

7条回答
  •  野的像风
    2021-01-31 03:39

    @BenLu and other users who are facing problem of the function are never getting called is because of following reason: As the delegate inbuild function bydefaults return void instead of BOOL this is how it should be as follows:

     -(void)textFieldDidBeginEditing:(UITextField *)textField
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.35f];
        CGRect frame = self.view.frame;
        frame.origin.y = -100;
        [self.view setFrame:frame];
        [UIView commitAnimations];
    }
    
    -(void)textFieldDidEndEditing:(UITextField *)textField
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.35f];
        CGRect frame = self.view.frame;
        frame.origin.y = 100;
        [self.view setFrame:frame];
        [UIView commitAnimations];
    }
    

提交回复
热议问题