CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Apr 2016 |
SPMSupports SPM | ✗ |
Maintained by kaizeiyimi.
play animated images using player. Easy to associated with any thing which can draw UIImage.
support speed, skipFrames, displayLinkFrameInterval config. Auto preload and clear cache if needed.
updated to swift 2.2 and refined some code.
swift 2.2 is required. And better use framework.
In most scene, developer will async load image data rather than other ways.
import XLYAnimatedImage
// get data
let data = ... // load from some where, network or ...
// scale has a default value equals to screen scale, or you can specify it.
let animatedImage = AnimatedDataImage(data: data, scale: default)
// setup player and keep a reference.
let player = AnimatedImagePlayer(display: {[weak self] image, index in
self?.image = image
},
stop: {[weak self] in
self?.image = nil
})
// setup image
player.image = animatedImage
// set replay to true will replay animatedImage even if it's same object.
player.setImage(image, replay: true)
// config player
player.onTimeElapse = { [unowned self] time in
self.timeSlider.value = Float(time / self.imageView.xly_animatedImagePlayer!.totalTime)
}
player.speed = 2
player.skipFrames = true
player.displayLinkFrameInterval = 2
or use a helper extension method on UIImageView.
// set image
imageView.xly_setAnimatedImage(animatedImage, replay: true)
// get player and then config as you wish
let player = imageView.xly_animatedImagePlayer
see more in demo.
AnimatedImage
and can be playered with player.paused
, speed
, skipFrames
, displayLinkFrameInterval
config.frameIndex
for current image frame index, time
for current playing time.moveToFrameAtIndex(_:)
, can move to any time by calling moveToTime(_:)
.display
callback for you to display a frame, stop
callback for you to stop playing an image, and onTimeElapse
to nofify time changing.also at any time, you can change callbacks and image, and can also refresh an image’s playing by set param ‘replay’ to true
.
no apng support now cause I’m waiting for apple to support in iOS device. if you need it, you can write your own impl, it’s not difficult.