import UIKit
class ViewController: UIViewController {
@IBOutlet weak var ball: UIView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
UIView.animate(withDuration: 2.0) {
self.ball.center = CGPoint(x: 20, y: 20)
//如果使用了autolayout则添加以下代码
self.view.layoutIfNeeded()
}
}
}