美文网首页
AutoLayout 动画

AutoLayout 动画

作者: zjunchao | 来源:发表于2016-07-15 16:43 被阅读70次

AutoLayout 动画

how to animate constraint changes?


  • Need call layoutIfNeeded within the animation block.
  • Need to call it specifically on the parent view, not the child view that has the constraints attached to it.

e.g:

- (void)moveBannerOffScreen {
    [self.view layoutIfNeeded];     // parent view call layoutIfNeeded 

    _addBannerDistanceFromBottomConstraint.constant = -32;
    [UIView animateWithDuration:5
        animations:^{
            [self.view layoutIfNeeded]; // Called within the block 
        }];
}

- (void)moveBannerOnScreen { 
    [self.view layoutIfNeeded];

    _addBannerDistanceFromBottomConstraint.constant = 0;
    [UIView animateWithDuration:5
        animations:^{
            [self.view layoutIfNeeded]; // Called on parent view
        }];
    bannerIsVisible = TRUE;
}

相关文章

网友评论

      本文标题:AutoLayout 动画

      本文链接:https://www.haomeiwen.com/subject/vsvyjttx.html