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;
}