[Swift通天遁地]八、媒体与动画-(8)使用开源类库快速实现位移动画

本文将演示使用第三方类库,快速实现位移动画。

首先确保已经安装了所需的第三方类库。双击查看安装配置文件【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 }

猜你喜欢

转载自www.cnblogs.com/strengthen/p/10354552.html