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];
}