0

I am attempting to make my item "glow" every 3 seconds changing its alpha from a high to low value and back. It however "flickers" and basically changes every 0.2 seconds from color to color randomly. I have pasted the method below. Its probably something to do with when completion is called but not sure?

-(void)showLoading{
    [self.postTableView setHidden:YES];
    self.isLoading = true;
    //Disappear
    [UIView animateWithDuration:1.5 animations:^(void) {
        self.loadingLabel.alpha = 0.8;
        self.loadingLabel.alpha = 0.3;
    }
    completion:^(BOOL finished){
            //Appear
            [UIView animateWithDuration:1.5 animations:^(void) {
            self.loadingLabel.alpha = 0.3;
            self.loadingLabel.alpha = 0.8;
            }completion:^(BOOL finished2){
                if(true){
                    [self showLoading];
                }
            }];
    }]; }
John
  • 1,677
  • 4
  • 15
  • 26

2 Answers2

2
self.loadingLabel.alpha = .8;
[UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
    self.loadingLabel.alpha = .3;
} completion:nil];

UIViewAnimationOptionAutoreverse & UIViewAnimationOptionRepeat can help you.

you can stop it by

self.loadingLabel.alpha = .8;

or the other animation.

[UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    self.loadingLabel.alpha = .8;
} completion:nil];

UIViewAnimationOptionBeginFromCurrentState is a useful option for you to stop your animation by the other animation.

Mornirch
  • 1,144
  • 9
  • 10
-2
-(void)viewDidLoad{
//use schedule timer to call repeatedly showLoading method until loading done
}
-(void)showLoading{
    [self.postTableView setHidden:YES];
    self.isLoading = true;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    self.loadingLabel.alpha = 0.3;
    [UIView commitAnimations];


    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    self.loadingLabel.alpha = 0.8;
    [UIView commitAnimations];
}
Mrugesh Tank
  • 3,495
  • 2
  • 29
  • 59