AutoLayout面试题记录-用NSLayoutConstraint写动画

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var topY: NSLayoutConstraint!
    @IBOutlet weak var destinationBtn: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        

    }

    @IBAction func click(_ sender: UIButton) {

        UIView.animate(withDuration: 1, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
            self.topY.constant = 200
            self.view.layoutIfNeeded()
        }) { (true) in
            
        }
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

storyboard中2个按钮,一个点击,一个移动动画用的

posted @ 2017-09-14 19:34  liuw_flexi  阅读(320)  评论(0编辑  收藏  举报