点击textField,上下移动View的通用的方法。

- (void) textFieldDidBeginEditing:(UITextField *)textField

{

//    [self animateTextField:textField up:YES];

    [ViewControllerFactoryanimateTextField:textField up:YESviewController:self];

}

- (void) textFieldDidEndEditing:(UITextField *)textField

{

//    [self animateTextField:textField up:NO];

    [ViewControllerFactoryanimateTextField:textField up:NOviewController:self];

}

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

{

    const int movementDistance = -textField.tag;

    const float movementDuration = 0.3f;

    

    int movement = (up ? movementDistance: -movementDistance);

    

    [UIViewbeginAnimations:@"animateTextField"context:nil];

    [UIViewsetAnimationBeginsFromCurrentState:YES];

    [UIView setAnimationDuration:movementDuration];

    

    self.view.frame = CGRectOffset(self.view.frame, 0, movement);

    [UIViewcommitAnimations];

}

猜你喜欢

转载自zhangmingwei.iteye.com/blog/2120151