-1

I have a UIImageView that I set a placeholder image in it, Then I want to gradually set the real image to it at the end, But this change should be according to the progress of downloading another file. (Not the image)

When the file is 10% the image fades in by 10% then 20 till it is 100% exchanged with the previous image.

I have seen code using CATransition But I don't know how to use it in this case.

You may want to check this answer. Transition from image to another

Community
  • 1
  • 1
Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45
  • did u try changing the alpha value based on the download percentage? How did u calculate the download percentage ? – Teja Nandamuri Nov 05 '15 at 18:47
  • if you are downlaoding the image in form of byte, you need to convert the bits into image sequentially depending on your dwonload percentage, and then load the image to imagview – Teja Nandamuri Nov 05 '15 at 19:09
  • Oh you got me wrong. I am downloading another big file and I have its image. I want to fade in the image showing the progress of the download. Thanks I am going to try setting the alpha gradually. – Khaled Annajar Nov 05 '15 at 19:13

1 Answers1

0

Try something like this:

Here I am reducing the alpha value every second by using the NSTimer. YOu can replace this later with your own timer which delas with the download progress.

-(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;

}
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109