简体   繁体   中英

make a swift custom animation

I want to make an animation using swift. When the user is authenticated, the ViewController split from the middle, the top part goes up and the bottom part goes down.

在此处输入图像描述

You can use constraints and UIView.animate()

Assume there are two view in this view controller. Let's create two new outlet for top and bottom view constraint.

        @IBOutlet weak var topViewTopConstraint: NSLayoutConstraint!    
        @IBOutlet weak var bottomViewBottomConstraint: NSLayoutConstraint!

then when user click button, this function should call;

func showAnimation() {
    UIView.animate(withDuration: 1) {
        topViewTopConstraint.constant = -(topView.frame.height)
        bottomViewBottomConstraint.constant =  -(bottomView.frame.height)
        self.view.layoutIfNeeded()
    }
}

Also you can call completion handler with animate function. When animation finish you can load or show next view controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM