IOS键盘出现时视图上移

来源:互联网 发布:mac os x install esd 编辑:程序博客网 时间:2024/05/16 09:38

- (void)textFieldDidBeginEditing:(UITextField *)textField

    {

        [self animateTextField: textField up: YES];

    }


    - (void)textFieldDidEndEditing:(UITextField *)textField

    {

        [self animateTextField: textField up: NO];

    }



    - (void) animateTextField: (UITextField*) textField up: (BOOL) up

    {

        const int movementDistance = 80; // 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];

    }

0 0
原创粉丝点击