ios - 为什么不是所有的 NSLayoutconstraints 都随动画变化,如何解决?

标签 ios swift nslayoutconstraint

我在 ViewController 中有两个 subview ,一个接一个(第一个的底部连接到第二个的顶部)

第一个 View 正在改变它的高度动画(下面的例子),所以我预计第二个 View 也会随着动画下降,但它不是..

如何制作动画?

第一个 View 的动画 block

func animate(){
    layoutIfNeeded()
    UIView.animateWithDuration(1){
        self.labelHeight.constant = 70 // this is constraint
        self.layoutIfNeeded()
        }
}

enter image description here

最佳答案

兄弟 View 之间的约束被添加到它们共享的 super View 中,因此您应该对其调用 layoutIfNeeded()。例如:

func animate(){
    self.superview?.layoutIfNeeded()
    UIView.animateWithDuration(1){
        self.labelHeight.constant = 70 // this is constraint
        self.superview?.layoutIfNeeded()
        }
}

关于ios - 为什么不是所有的 NSLayoutconstraints 都随动画变化,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37684176/

相关文章:

ios - 链接到变量的 Xcode iOS 约束

iOS leftSpacingConstraint 相对于屏幕高度

ios - 如何调试通用链接

swift - "Generic parameter could not be inferred"在 SwiftUI UIViewRepresentable

swift - 触摸时向 SKSpriteNode 添加动画(Swift)

ios - 在第二个动画之前查看跳跃

ios - UIPopoverPresentationController 将弹出窗口显示为全屏

ios - 核心数据建模问题(如何根据关系的关系更新属性?)

objective-c - UICollectionView 布局间距问题。单元格之间的空间太大

ios - Cell 的附件不断截断 UILabel