0

我试图让我的项目每 3 秒“发光”一次,将其 alpha 从高值更改为低值并返回。然而,它“闪烁”并且基本上每 0.2 秒从一种颜色随机变化一次。我已经粘贴了下面的方法。它可能与何时调用完成但不确定有关?

-(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];
                }
            }];
    }]; }
4

2 回答 2

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

UIViewAnimationOptionAutoreverse & UIViewAnimationOptionRepeat可以帮助你。

你可以通过

self.loadingLabel.alpha = .8;

或其他动画。

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

UIViewAnimationOptionBeginFromCurrentState是一个有用的选项,可让您通过其他动画停止动画。

于 2015-03-28T03:46:36.270 回答
-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];
}
于 2015-03-28T03:29:17.200 回答