是否可以通过更改约束来制作 UIView 动画?
基本上,我想为具有 x、y、高度和宽度约束的 myv
(UIView) 设置动画,使用:UIView.animateWithDuration(1.5) {}
通过更改旧的约束。
最佳答案
是的,这是可能的。你可以这样做:
func AnimateHeight() {
UIView.animateWithDuration(1.5, animations: {
self.heightCons.constant = 250 // Some value
self.view.layoutIfNeeded()
})
}
其中 self.heightCons
是 UIView
高度约束的 IBOutlet
。
如果您不使用 Storyboard,您可以查看 how to create layout constraints programmatically .
有关核心动画和自动布局的信息:Combining autolayout with core animation
关于ios - 带约束的 Swift 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38575410/