是否可以通过更改约束来制作UIView动画?
基本上,我想通过更改旧约束来使用:myv
来设置具有x,y,高度和宽度约束的UIView.animateWithDuration(1.5) {}
(UIView)。
答案 0 :(得分:20)
是的,这是可能的。你可以这样做:
func AnimateHeight() {
UIView.animateWithDuration(1.5, animations: {
self.heightCons.constant = 250 // Some value
self.view.layoutIfNeeded()
})
}
self.heightCons
与IBOutlet
上的身高限制UIView
的位置。
如果您不使用故事板,可以查看how to create layout constraints programmatically。
有关核心动画和自动布局的信息:Combining autolayout with core animation