gif view to swift

This commit is contained in:
Pfeil, Scott Robert 2019-03-19 13:13:18 -04:00
parent 9b6df99126
commit bef105decd

View File

@ -8,7 +8,7 @@
import UIKit
@objcMembers public class MFTransparentGifView: FLAnimatedImageView {
@objcMembers public class MFTransparentGIFView: FLAnimatedImageView {
var imageData: Data?
/** Creates the GIF display view with the passed in frame.
@ -19,16 +19,20 @@ import UIKit
LoopCompletionBlock: a block called whenever the gif finishes a loop.
animatedImage : set as nil when use this view in reusable cell
*/
init(withFrame frame: CGRect, imageName: String, startImmediately: Bool, duration: TimeInterval, loopCompletionBlock: ((UInt) -> Void)?) {
@objc public init(withFrame frame: CGRect, imageName: String, startImmediately: Bool, duration: TimeInterval, loopCompletionBlock: ((UInt) -> Void)?) {
super.init(frame: frame)
loadImage(imageName, startImmediately: startImmediately, duration: duration, loopCompletionBlock: loopCompletionBlock)
}
public override init(frame: CGRect) {
super.init(frame: frame)
loadImage(imageName: imageName, startImmediately: startImmediately, duration: duration, loopCompletionBlock: loopCompletionBlock)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func loadImage(imageName: String, startImmediately: Bool, duration: TimeInterval, loopCompletionBlock: ((UInt) -> Void)?) {
func loadImage(_ imageName: String, startImmediately: Bool, duration: TimeInterval, loopCompletionBlock: ((UInt) -> Void)?) {
contentMode = UIView.ContentMode.scaleAspectFill
clipsToBounds = true
@ -52,7 +56,7 @@ import UIKit
}
}
func loadGifWithData(imageData: Data) {
public func loadGifWithData(_ imageData: Data) {
contentMode = UIView.ContentMode.scaleAspectFill
clipsToBounds = true
backgroundColor = .clear
@ -61,7 +65,7 @@ import UIKit
performAnimations()
}
func performAnimations() {
public func performAnimations() {
animatedImage = FLAnimatedImage(animatedGIFData: imageData, optimalFrameCacheSize: 250, predrawingEnabled: true)
}
}