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个按钮,一个点击,一个移动动画用的