[Swift通天遁地]八、媒體與動畫-(8)使用開源類庫快速實現位移動畫
阿新 • • 發佈:2019-02-07
clas for resources control xcode can 安裝配置 gre 安裝完成
本文將演示使用第三方類庫,快速實現位移動畫。
首先確保已經安裝了所需的第三方類庫。雙擊查看安裝配置文件【Podfile】
1 platform :ios, ‘8.0‘ 2 use_frameworks! 3 4 target ‘DemoApp‘ do 5 source ‘https://github.com/CocoaPods/Specs.git‘ 6 pod ‘Cheetah‘ 7 end
根據配置文件中的相關設置,安裝第三方類庫。
安裝完成之後,雙擊打開項目文件【DemoApp.xcodeproj】
在左側的項目導航區,打開視圖控制器的代碼文件【ViewController.swift】
1 import UIKit 2 //引入已經安裝的第三方類庫 3 import Cheetah 4 5 class ViewController: UIViewController { 6 //添加一個未初始化的屬性 7 var box : UIView! 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 // Do any additional setup after loading the view, typically from a nib.11 12 //初始化一個普通的視圖對象, 13 //給該視圖對象添加位移動畫。 14 box = UIView(frame:CGRect(x: 0, y: 100, width: 100, height: 100)) 15 //設置視圖對象的背景顏色為橙色。 16 box.backgroundColor = UIColor.orange 17 //將視圖對象添加到根視圖 18 self.view.addSubview(box) 19 20 //調用視圖對象的擴展方法,將視圖對象通過動畫的方式,向右移動100點的距離。21 box.cheetah.move(100,0).run() 22 } 23 24 override func didReceiveMemoryWarning() { 25 super.didReceiveMemoryWarning() 26 // Dispose of any resources that can be recreated. 27 } 28 }
[Swift通天遁地]八、媒體與動畫-(8)使用開源類庫快速實現位移動畫