【问题标题】:Recursive animateWithDuration: animations: completion: method iOS递归animateWithDuration:动画:完成:方法iOS
【发布时间】:2015-03-28 02:57:25
【问题描述】:

我试图让我的项目每 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];
                }
            }];
    }]; }

【问题讨论】:

    标签: ios animation alpha animatewithduration


    【解决方案1】:
    self.loadingLabel.alpha = .8;
    [UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
        self.loadingLabel.alpha = .3;
    } completion:nil];
    

    UIViewAnimationOptionAutoreverseUIViewAnimationOptionRepeat 可以帮助您。

    你可以阻止它

    self.loadingLabel.alpha = .8;
    

    或其他动画。

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

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

    【讨论】:

    • 谢谢!以简单的方式解决了问题。
    【解决方案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];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      相关资源
      最近更新 更多