美文网首页
Masonry 通过 UIView 起动画时出现约束冲突,并且没

Masonry 通过 UIView 起动画时出现约束冲突,并且没

作者: NapoleonY | 来源:发表于2019-03-31 19:36 被阅读0次

概述

使用 UIView 起动画,通过 Masonry 设置的约束

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;

发现了两个问题

  1. 并没有动画效果
  2. Masonry 报问题:约束有冲突

原因

经过观察代码发现

  1. UIView 在使用 Masonry 设置约束时,当起动画时,需要在 animations Block 中调用 [self layoutIfNeeded] 刷新 superView
  2. 在 UIView animation 中需要使用 Masonry mas_remakeConstraints 更新约束,否则就会报 “约束冲突”的问题,因为 mas_makeConstraints 只负责新增约束,不能同时存在两条针对于同一对象的约束

其他

mas_updateConstraintsmas_remakeConstraints 的区别

  • update 会更新约束,如果出现有相同的约束方法,只是值不同,则会直接使用新的约束
  • remake 会清除掉之前的约束,重新设置约束

相关文章

网友评论

      本文标题:Masonry 通过 UIView 起动画时出现约束冲突,并且没

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