[Swift通天遁地]8、媒體與動畫-(6)使用開源類庫快速實現滑入動畫

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-yzflhriw-mc.html 
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html

目錄:[Swift]通天遁地Swiftios

本文將演示使用第三方類庫,快速實現一個從上向下滑入的動畫。git

首先確保已經安裝了所需的第三方類庫。雙擊查看安裝配置文件【Podfile】github

1 platform :ios, '12.0'
2 use_frameworks!
3 
4 target 'DemoApp' do
5     source 'https://github.com/CocoaPods/Specs.git'
6     pod 'Spring', :git => 'https://github.com/MengTo/Spring.git'
7 end

根據配置文件中的相關設置,安裝第三方類庫。swift

安裝完成以後,雙擊打開項目文件【DemoApp.xcodeproj】xcode

往項目中導入用於實現動畫的圖片素材。微信

在左側的項目導航區,打開視圖控制器的代碼文件【ViewController.swift】ide

 1 import UIKit
 2 //引入已經安裝的第三方類庫
 3 import Spring
 4 
 5 class ViewController: UIViewController {
 6     
 7     override func viewDidLoad() {
 8         super.viewDidLoad()
 9         // Do any additional setup after loading the view, typically from a nib.
10         
11         //從項目中讀取一張圖片素材
12         let image = UIImage(named:"star")
13         //初始化一個動畫圖像視圖對象
14         let imageView = SpringImageView(image: image)
15         
16         //設置圖像視圖的顯示區域
17         imageView.frame = CGRect(x: 0, y: 0, width: 80, height: 80)
18         //將圖像視圖移動到水平方向上的中心位置,
19         imageView.center = CGPoint(x: 160, y: 160)
20         //接着將圖像視圖添加到根視圖。
21         self.view.addSubview(imageView)
22         
23         //設置動畫圖像視圖對象的動畫類型,
24         //第三方類庫共提供了26個不一樣的動畫。
25         imageView.animation = "squeezeDown"
26         //設置動畫圖像視圖對象,能夠進行動畫的自動播放。
27         imageView.autostart = true
28     }
29     
30     override func didReceiveMemoryWarning() {
31         super.didReceiveMemoryWarning()
32         // Dispose of any resources that can be recreated.
33     }
34 }
相關文章
相關標籤/搜索