【问题标题】:Swift animation with constraint带约束的 Swift 动画
【发布时间】:2016-11-29 05:56:39
【问题描述】:

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

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

【问题讨论】:

    标签: ios swift constraints core-animation


    【解决方案1】:

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

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

    其中self.heightConsIBOutletUIView 的高度限制。

    如果您不使用情节提要,可以查看how to create layout constraints programmatically

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 2015-02-06
    • 2013-07-11
    • 2018-06-16
    相关资源
    最近更新 更多