【问题标题】:iOS8: View to Layer AnimationiOS8:视图到图层动画
【发布时间】:2015-08-25 22:23:26
【问题描述】:

我想将下面这个基于View 的动画转换为基于Layer 的动画。

@IBOutlet weak var constraintTopContainerHeight: NSLayoutConstraint!

override func viewDidLoad() {
    super.viewDidLoad()

    var value:CGFloat

    switch (someTag)
    {
    case 1:
        value = CGFloat(self.view.bounds.height / 3)
    case 2:
        value = CGFloat(self.view.bounds.height / 2)
    case 3:
        value = CGFloat(self.view.bounds.height * 0.8)
    default:
        value = 0.0
    }

    UIView.animateWithDuration(1.5, delay: 0.0,
        usingSpringWithDamping: 0.3, initialSpringVelocity: 0.0,
        options: nil, animations: {

        self.constraintTopContainerHeight.constant = value
        self.view.layoutIfNeeded()

        }, completion: nil)
     }
}

如何获得Constraint 以使用基于Layer 的动画而不是当前基于View 的动画。请代码。

【问题讨论】:

    标签: swift ios8 autolayout uianimation


    【解决方案1】:

    首先,您应该在 UIView 动画之外设置约束。

    此外,您不能使用 Core Animation 为约束设置动画。

    Apple 的自动布局指南解释了这一点。

    https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-07
      • 1970-01-01
      • 1970-01-01
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      • 1970-01-01
      相关资源
      最近更新 更多