iOS專案開發實戰——製作檢視的縮放動畫

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

     檢視的大小應該是隨時可控的。今天我們就來實現對一個View的縮放動畫。該動畫的實現與位移動畫,透明度動畫稍有不同。具體實現如下:

import UIKit

class ScaleViewController: UIViewController {

    
    
    @IBOutlet weak var greenSquare: UIView!
    
    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.
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        func anim(){
        
            self.greenSquare.transform = CGAffineTransformMakeScale(0.5, 0.5)//縮小為原來的0.5倍;
        }
        
        
        UIView.animateWithDuration(1, animations: anim)
        
        
        
    }

}

(3)執行程式,發現View可以變為原來X,Y軸上的0.5倍。


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

相關文章