iOS專案開發實戰——製作檢視的旋轉動畫

乞力馬紮羅的雪CYF發表於2015-08-20

     這裡我們將會實現一個View的旋轉。具體實現如下:

(1)在Main.storyboard中拖入一張圖片,繫結到程式碼中,等下要對這張圖片進行旋轉。

(2)程式碼實現如下:

import UIKit

class RotationViewController: UIViewController {

    
    @IBOutlet weak var wheel: UIImageView!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func spin(){
    
        UIView.animateWithDuration(1, delay: 0, options: .CurveLinear, animations: {
        
            self.wheel.transform = CGAffineTransformRotate(self.wheel.transform, CGFloat(360))//第二個引數是角度;
            }) {
        
                //結束後仍舊呼叫spin()函式;
                (finished)-> Void in
                self.spin()
        }
        
    }//spin()
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.spin()
    }

}

(3)執行結果:

可以看到那張圖片在進行無限迴圈的旋轉中。。。


github主頁:https://github.com/chenyufeng1991  。歡迎大家訪問!

相關文章