带约束的Swift动画

时间:2016-07-25 18:52:42

标签: swift constraints core-animation

是否可以通过更改约束来制作UIView动画?

基本上,我想通过更改旧约束来使用:myv来设置具有x,y,高度和宽度约束的UIView.animateWithDuration(1.5) {}(UIView)。

1 个答案:

答案 0 :(得分:20)

是的,这是可能的。你可以这样做:

func AnimateHeight() {
    UIView.animateWithDuration(1.5, animations: {
         self.heightCons.constant = 250 // Some value
         self.view.layoutIfNeeded()    
    })
}

self.heightConsIBOutlet上的身高限制UIView的位置。

如果您不使用故事板,可以查看how to create layout constraints programmatically

有关核心动画和自动布局的信息:Combining autolayout with core animation