//
// ViewController.swift
// Loader
//
// Created by Pawan Kumar on 28/09/17.
// Copyright © 2017 Pawan Kumar. All rights reserved.
//
import UIKit
import FLAnimatedImage
class ViewController: UIViewController {
@IBOutlet weak var animatedImageView: FLAnimatedImageView!
// @IBOutlet weak var checkImageView: FLAnimatedImageView!
override func viewDidLoad() {
super.viewDidLoad()
let url = Bundle.main.path(forResource: "Loader", ofType: "gif")
print(url!)
let data=NSData(contentsOfFile: url!)
//print(data)
let fff=FLAnimatedImage(gifData: data as Data?)
let imageView=FLAnimatedImageView()
imageView.animatedImage=fff
//
// imageView.frame=CGRect(x: animatedImageView.frame.minX, y: animatedImageView.frame.minY, width: animatedImageView.frame.width, height: animatedImageView.frame.height)
imageView.frame=CGRect(x: animatedImageView.frame.minX, y: animatedImageView.frame.minY, width: animatedImageView.frame.width, height: animatedImageView.frame.height)
print(imageView.currentFrameIndex)
imageView.clipsToBounds=true
self.view.addSubview(imageView)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Tạo một bộ điều khiển xem như thể hiện trong đoạn code trên. Lưu ý: - trong khi tạo một lần xem hình ảnh trong bảng câu chuyện, hãy đặt lớp chế độ xem hình ảnh là FLanimatedImageView.
Nó sẽ hoạt động.
Ở đây Loader.gif là hình ảnh GIF.
Nguồn
2017-09-29 03:49:22
bạn có thể sử dụng thư viện https://github.com/Flipboard/FLAnimatedImage –
tải hình ảnh GIF này trong Swift: https://iosdevcenters.blogspot.com/2016/08/load-gif-image-in-swift_22. html –