我正在使用UIImageView
和NSTimer
制作幻灯片。一切都运行正常,除了第一次调用transitionWithView
方法时,动画发生了,它只是改变图像而没有交叉溶解,之后,交叉溶解在每个图像上都有效更改。
请在代码中找到错误:
-(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];
}
这里是handleTimer
代码:
- (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];
}