Note: How to Animate with Auto Layout Constraints

Author: Sean Allen Video URL: How to Animate with Auto Layout Constraints Introduction: In this video we walk through how to create animations by adjusting the auto layout constraints and object, such as a UIImageView, UIButton, etc… This tutorial was done in Swift 4.2 and Xcode 10.

Add IBoutlet of constraints by ctrl+drag

Add IBoutlet of constraints

Ways to animate with auto layout constraints

Add IBoutlet of the target constraint, and change its values, then update.

    @IBOutlet weak var logoTopConstraint: NSLayoutConstraint!
    func animateLogoTop() {
        logoTopConstraint.constant = 50
        UIView.animate(withDuration: 0.4) {
            self.view.layoutIfNeeded()
        }
    }

Change the variable of programmed constraints and update

    func animateStartButtonCenter() {
        startButtonCenterYConstraint.constant = view.center.x
        UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 4, options: .curveEaseOut, animations: {
            self.view.layoutIfNeeded()
        }, completion: nil)
    }
     
Advertisements

分类:iOS

Tagged as: ,

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.