Core Animation移动图片

梁新觉
2023-12-01
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链接

 类似资料: