-1

我有一个UIImageView,我在里面设置了一个占位符图像,然后我想在最后逐步设置真实图像,但是这个改变应该是根据下载另一个文件的进度。(不是图片)

当文件为 10% 时,图像淡入 10%,然后淡入 20,直到 100% 与前一个图像交换。

我见过使用CATransition的代码,但我不知道在这种情况下如何使用它。

你可能想检查这个答案。从图像过渡到另一个

4

1 回答 1

0

尝试这样的事情:

在这里,我使用 NSTimer 每秒减少 alpha 值。您可以稍后用您自己的计时器替换它,该计时器会随着下载进度而延迟。

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    _count=1;  //downalod count

    NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                      target:self
                                                    selector:@selector(handleTimer:)
                                                    userInfo:@"someString" repeats:YES];

}

- (void)handleTimer:(NSTimer*)theTimer {
     NSLog (@"Got the string: %@", (NSString*)[theTimer userInfo]);
    [self changeAlpha:_count];
    _count=_count-0.1;

}

-(void)changeAlpha:(float) num{
            _imgView.alpha=num;

}
于 2015-11-05T19:25:12.947 回答