user1107173
user1107173

Reputation: 10744

iOS8: View to Layer Animation

I would like to convert this View based animation below into Layer based.

@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)
     }
}

How do I get a Constraint to use Layer based animation instead of the current View based animation. Code please.

Upvotes: 0

Views: 26

Answers (1)

Chris Slowik
Chris Slowik

Reputation: 2879

First of all, you should set your constraint outside of your UIView animation.

Also, you can't animate constraints with Core Animation.

The auto-layout guide from Apple explains.

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

Upvotes: 1

Related Questions