zoukankan      html  css  js  c++  java
  • [Swift通天遁地]八、媒体与动画-(10)在项目中播放GIF动画

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
    ➤微信公众号:山青咏芝(shanqingyongzhi)
    ➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/
    ➤GitHub地址:https://github.com/strengthen/LeetCode
    ➤原文地址:https://www.cnblogs.com/strengthen/p/10354775.html 
    ➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
    ➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

    目录:[Swift]通天遁地Swift

    本文将演示使用第三方类库播放GIF动画。

    首先确保已经安装了所需的第三方类库。双击查看安装配置文件【Podfile】

    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

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

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

    往项目中导入GIF文件。

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

     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,  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 }

  • 相关阅读:
    Java速成笔记
    C语言学习笔记
    形式语义05 Semantics
    密码学04 PRG&PRF
    形式语义04 Types
    密码学03 Computational
    形式语义03 Lambda
    密码学02 Perfect
    形式语义01 Intro
    密码学01 Intro
  • 原文地址:https://www.cnblogs.com/strengthen/p/10354775.html
Copyright © 2011-2022 走看看