【发布时间】:2017-04-17 15:10:53
【问题描述】:
初始约束...
let conBottom = imageView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: imageView.frame.height)
那么……
UIView.animate(
withDuration: 0.67,
delay: 2.0,
animations: {
conBottom.constant = imageView.frame.height
self.view.layoutIfNeeded()
},
completion: nil
)
约束的常数没有改变,但动画会导致视图从屏幕末端消失。
如果我在动画块中注释掉常量的设置,那么视图不会移动。
为什么视图会移动?
【问题讨论】:
-
打印原始值和更改后的值。控制台中有任何警告吗?
-
在动画块中将其设置为与动画块之前完全相同的值有什么意义? (作为一般规则,您应该在调用
animate()之前设置自动布局约束的常量,并让animate()更新布局。) -
@NRitH 消除我的不理解。
-
@NRitH 我不同意你的一般规则,特别是如果有 2 秒的延迟。
-
@Sulthan,你是对的;我没有注意到延迟。如果有任何延迟,则在动画开始之前布局已经刷新。
标签: swift uiview autolayout