小编Ale*_*ati的帖子

如果调用layoutIfNeeded(),UIView 约束将不会动画

我正在尝试对一个被约束 ( iconVerticalConstraint) 位于+100超级视图中心 Y ( ) 的视图进行动画处理,特别是0在动画后到达其右侧 ( ) 位置。这是我的代码:

self.view.layoutIfNeeded()

UIView.animateKeyframes(withDuration: 2, delay: 0, animations: {

    UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.25, animations:{
        self.iconVerticalConstraint.constant -= 20
    })

    UIView.addKeyframe(withRelativeStartTime: 0.25, relativeDuration: 0.75, animations:{
        self.iconVerticalConstraint.constant -= 80
    })
})
Run Code Online (Sandbox Code Playgroud)

我尝试遵循这个问题的答案,但这没有帮助,因为在我的情况下,我的视图包含更多子视图,本质上链接,并且放入layoutIfNeeded()我的动画块将使整个视图动画化,而不仅仅是那个约束。否则这种方法根本不会产生动画。

cocoa animation uiview ios swift

0
推荐指数
1
解决办法
3642
查看次数

标签 统计

animation ×1

cocoa ×1

ios ×1

swift ×1

uiview ×1