문제

I'm making app for time lapse photos, I'm using SDWebImage to download+cache photos from server, and I'd like to do slideshow from series of photos. I've tried SDWebImage's method setAnimationImagesWithURLs for UIImageView, which works, but I need to have more control(I don't want to animation start right after viewDidLoad,...).

I imagine that after view controller is shown, it starts to download photos from array of NSURLs, Only first picture is shown, there are play/stop/next controls, and user can tap on them to start animation...

In every tutorial on UIImageView animation, they load images into array, which is used as setAnimationImages:array, but after reading this answer, it looks like it's not a good idea.

So what's to proper way to do that?

도움이 되었습니까?

해결책 2

If you're running a slide show you'd usually have a nice transition animation between each of the images. As you say, you also want to pause, manually skip, etc.

Using a single image view won't necessarily work well for that. You may want to have 2 image views and use them in tandem (fading or moving in and out of the screen).

SDWebImage is able to download the image in the background for you (SDWebImageDownloader.sharedDownloader) so you can easily decouple the downloading from your slide show animation.

NSTimer is suitable for running your slideshow. You can start and invalidate it as required. The method that runs to move to the next image can also be run explicitly is required.

So, what you want isn't image view animation. It's a slideshow components, which happens to be implemented with a (couple of) image view(s).

That all said, leverage existing code: search CocoaControls.

다른 팁

For anyone, who would need this, based on Wain's answer, I've come up with solution using SDWebImage and KASlideShow, it works pretty well.

Here's my code:

    self.slideshow = [[KASlideShow alloc] initWithFrame:CGRectMake(0,0,320,225)];
    [self.slideshow setDelay:1]; // Delay between transitions
    [self.slideshow setTransitionDuration:1]; // Transition duration
    [self.slideshow setTransitionType:KASlideShowTransitionFade]; // Choose a transition type (fade or slide)
    [self.slideshow setImagesContentMode:UIViewContentModeScaleAspectFill]; // Choose a content mode for images to display
    self.slideshow.delegate = self;

    SDWebImageManager *manager = [SDWebImageManager sharedManager];
    for (NSURL *snap in self.imagesURLArray) {
        [manager downloadWithURL:snap options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
            if (image)
            {
                [self.slideshow addImage:image];
            }
        }];
    }

    // do not forget to add slideshow as a subview
    [self.view addSubview:self.slideshow];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top