3

I'm making a slideshow using UIImageView and NSTimer. Everything is working fine except that for the first time when transitionWithView method is called, the animation DOESN'T happen, it just changes the image without cross-dissolve, and after that, the cross dissolve works at every image change.

Please can you find the error in my code:

-(void) startSlideShow
{

NSURL *imageURL = [NSURL URLWithString:[self.arrImageLinks objectAtIndex:currentImage]];

[UIView transitionWithView:self.imageView
                      duration:1.0f
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{

                        [manager downloadImageWithURL:imageURL
                                              options:0
                                             progress:^(NSInteger receivedSize, NSInteger expectedSize) {

                                             }
                                            completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                                                if (image) {

                                                    [self.imageView setImage:image];
                                                }
                                            }];
                    } completion:nil];

timer = [NSTimer timerWithTimeInterval:6.0 target:self selector:@selector(handleTimer:) userInfo:nil repeats:YES];

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];

}

Here's the handleTimer code :

- (void) handleTimer: (NSTimer *) timer {

    currentImage++;
    if ( currentImage >= self.arrImageLinks.count )
        currentImage = 0;


    NSURL *imageURL = [NSURL URLWithString:[self.arrImageLinks objectAtIndex:currentImage]]; 

[UIView transitionWithView:self.imageView
                          duration:1.0f
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^{

                            [manager downloadImageWithURL:imageURL
                                                  options:0
                                                 progress:^(NSInteger receivedSize, NSInteger expectedSize) {

                                                 }
                                                completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                                                    if (image) {

                                                        [self.imageView setImage:image];
                                                    }
                                                }];
                        } completion:nil];

}
Hyder
  • 1,163
  • 2
  • 13
  • 37
  • Please check this link http://stackoverflow.com/questions/7616655/uiview-transitionwithview-doesnt-work?rq=1. It might help you. – Rajesh Maurya Jun 15 '15 at 11:15
  • Were you able to figure this out? I have the same issue, where it only works first time. – Gizmodo Oct 20 '16 at 14:18
  • @gizmodo I don't remember if I got it working or not, but I started using [this](https://github.com/kirualex/KASlideShow) awesome slideshow library which let us create slideshows easily. Go check it if u want to implement image slideshows. – Hyder Oct 21 '16 at 12:42
  • Hello I have similar issue can you find anything ? – Yogesh Patel Jul 01 '19 at 07:12
  • @YogeshPatel Please check my comment above. I used KASlideShow library and it served the purpose. – Hyder Jul 03 '19 at 05:39
  • Okay Thanks will check and inform you – Yogesh Patel Jul 04 '19 at 05:08

0 Answers0