Core Animation移動圖片

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()
        }
    }

}

Demo-2鏈接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章