[Swift通天遁地]8、媒体与动画-(10)在项目中播放GIF动画

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-dgtkuycq-mc.html 
➤若是连接不是山青咏芝的博客园地址,则多是爬取做者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持做者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html

目录:[Swift]通天遁地Swiftios

本文将演示使用第三方类库播放GIF动画。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 'SwiftGifOrigin', '~> 1.6.1'
7 end

根据配置文件中的相关设置,安装第三方类库。swift

安装完成以后,双击打开项目文件【DemoApp.xcodeproj】xcode

往项目中导入GIF文件。微信

在左侧的项目导航区,打开视图控制器的代码文件【ViewController.swift】ide

 1 import UIKit
 2 //引入已经安装的第三方类库
 3 import SwiftGifOrigin
 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 imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 280, height: 170))
13         //调用图像视图对象的扩展方法,读取项目中的动画文件。
14         imageView.loadGif(name: "fire")
15         //将图像视图对象移动到根视图的中心位置
16         imageView.center = self.view.center
17         
18         //将图像视图添加到根视图
19         self.view.addSubview(imageView)
20         //设置根视图的背景颜色为黑色
21         self.view.backgroundColor = UIColor.black
22     }
23 
24     override func didReceiveMemoryWarning() {
25         super.didReceiveMemoryWarning()
26         // Dispose of any resources that can be recreated.
27     }
28 }
相关文章
相关标签/搜索