Objective c 在ios上延迟后启动UIActivityIndicator

Objective c 在ios上延迟后启动UIActivityIndicator,objective-c,ios,uiactivityindicatorview,Objective C,Ios,Uiactivityindicatorview,仅当操作花费太多时间时,我才想启动UIActivityIndicator: - (void) continueLaunch { //operations //..... [activityIndic stopAnimating]; } //my current method - (void)lauchApplication { [activityIndic startAnim

仅当操作花费太多时间时,我才想启动UIActivityIndicator:

    - (void) continueLaunch {

        //operations
        //.....
        [activityIndic stopAnimating];

    }

    //my current method
    - (void)lauchApplication {          
        [activityIndic startAnimating];
        [self performSelector:@selector(continueLaunch) withObject:nil afterDelay:0.0f];
    }   

    //what I want to do
    - (void)lauchApplication {
         if ([self performSelector:@selector(continueLaunch) withObject:nil afterDelay:0.0f]duration > 1 second){
              [activityIndic startAnimating];
         } 
    }

我该怎么做呢?

我认为最好的办法是在您想要等待的持续时间之后启动指示器,如果在该持续时间之前的某个时刻发生了什么事情,您可以取消它:

[self performSelector:@selector(startAnimation) withObject:nil afterDelay:1.0f]
对于取消它(来自Apple Doc):

要取消排队消息,请使用 取消以前的性能请求,目标:或 cancelPreviousPerformRequestsWithTarget:selector:object:method


一种可能的解决办法是:

  • 创建一个计时器
  • 每隔X秒在另一个线程中启动方法B
  • 在方法B中,检查:如果方法A正在进行且计时器为>Y time,则开始设置活动指示器的动画