简体   繁体   中英

I use the UIView `animateWithDuration:animations:` method to animate my view, it's bottom constant change, but it shows did not animate

I use the UIView animateWithDuration:animations: method to animate my view, it's bottom constant change, but it shows did not animate.

My code is below:

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottom_tableView;

...
// my animate method
- (void)hideSelf {
    [UIView animateWithDuration:0.5 animations:^{

        _upspringBackView.alpha = 0.f;
        _bottom_tableView.constant = -_tableView.bounds.size.height - 49;
    } completion:^(BOOL finished) {

        if (finished) {

            self.hidden = YES;
        }
    }];
}

I don't know why, my code is no problem.

If you want to animate the view by its NSLayoutConstraint, you should set the layoutIfNeeded method in the animations block:

Try this:

    _bottom_tableView.constant = -_tableView.bounds.size.height - 49;

    [UIView animateWithDuration:0.5 animations:^{

        _upspringBackView.alpha = 0.f;
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {

        if (finished) {

            self.hidden = YES;
        }
    }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM