ibireme / YYImage

Image framework for iOS to display/encode/decode animated WebP, APNG, GIF, and more.
MIT License
1.77k stars 482 forks source link

YYAnimatedImageView play animation from end to start? #47

Open magavelis opened 8 years ago

magavelis commented 8 years ago

How could I implement functionality to make YYAnimatedImageView to play animations in ping pong style? When animation reach a last frame it should continue animating till reach first frame using negative step. This should be continued till total loop count is reached.

ibireme commented 8 years ago

Not supported currently.

You may set currentAnimatedImageIndex manually, but it may costs lots of CPU if the image is compressed with dispose methods.

wang9262 commented 8 years ago

I add an observer for currentAnimatedImageIndex,and when it reach the last frame,I change currentAnimatedImageIndex.However,there happens a dead lock.Some code and the call stack are described as below.

code:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
    if ([keyPath isEqualToString:NSStringFromSelector(@selector(currentAnimatedImageIndex))]) {
        YYAnimatedImageView *imageView = object;
        if (imageView.currentAnimatedImageIndex == lastFrameIndex) {
            imageView.currentAnimatedImageIndex = secondFrameIndex;
        }
    }
}

call stack: ScreenShot

Any ideas?Am I using in a incorrect way?