ios - 带约束的 Swift 动画

标签 ios swift constraints core-animation

是否可以通过更改约束来制作 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.heightConsUIView 高度约束的 IBOutlet

如果您不使用 Storyboard,您可以查看 how to create layout constraints programmatically .

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

关于ios - 带约束的 Swift 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38575410/

相关文章:

java - 更改Hibernate中一对多单向关系中的外键约束名称

mysql - 如何在 MySQL 中使用 NULL 值进行唯一约束

xcode - 快速从另一个类(class)获取游戏中心的分数

SwiftUI - NavigationView 和选项卡栏的屏幕位置问题

iphone - instantiateViewControllerWithIdentifier 显示空白 View (xcode 4.5)

ios - NavigationBar 为一个 View 设置 TitleColor

ios - SpriteKit 中使用模糊和阈值的水效果

c# - 类型参数的约束 - 其中 T : class

ios - UITextField - If 语句

iphone - 如何在ios中访问Salesforce附件正文(base64二进制数据)?