【发布时间】:2016-11-29 05:56:39
【问题描述】:
是否可以通过改变约束来制作 UIView 动画?
基本上,我想为具有 x、y、高度和宽度约束的 myv (UIView) 设置动画,使用:UIView.animateWithDuration(1.5) {} 通过更改旧约束。
【问题讨论】:
标签: ios swift constraints core-animation
是否可以通过改变约束来制作 UIView 动画?
基本上,我想为具有 x、y、高度和宽度约束的 myv (UIView) 设置动画,使用:UIView.animateWithDuration(1.5) {} 通过更改旧约束。
【问题讨论】:
标签: ios swift constraints core-animation
是的,这是可能的。你可以这样做:
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
【讨论】: