在 AutoLayout 和 Masonry 中使用[UIView animationWith...]]

问题描述:

一个UIImageView做动画时,未按设置的frame做动画。

原因:

由于用Masonry设置了约束,设置动画时,需要用updateConstraints重设约束


AutoLayout中例子如下所示:

[UIView animateWithDuration:2.0f delay:0  animations:^{

    // 修改 animationView 的约束

    animationView.widthConstraint.constant = 20.f;

    // 注意这里要调用 animationView 父视图的 layoutIfNeeded 方法,这里为superview

    [superview layoutIfNeeded];

} completion:^(BOOL finished) {

}];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容