UIView transitionWithView不能仅在第一次工作

时间:2015-06-15 10:09:01

标签: ios objective-c uiview uiimageview nstimer

我正在使用UIImageViewNSTimer制作幻灯片。一切都运行正常,除了第一次调用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];

}

0 个答案:

没有答案