活动指标持续5秒?

时间:2013-05-31 09:31:38

标签: ios objective-c nstimer uiactivityindicatorview

全部

我试图在UIActivityIndicator方法上运行viewdidappear 5秒钟。但我如何给活动指标设定时间限制(5秒)?

这是UIActivityIndicator

的代码
 UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc]     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    activityView.center=self.view.center;

    [activityView startAnimating];

    [self.view addSubview:activityView];

4 个答案:

答案 0 :(得分:5)

有一行,没有额外的依赖关系&条件:

[activityView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:5.0];

答案 1 :(得分:4)

将活动视图设置为在停止时自动隐藏

activityView.hidesWhenStopped = YES;

并像这样在5秒后隐藏它:

[activityView performSelector:@selector(stopAnimating) withObject:nil afterDelay:5.0];

这将允许您再次启动动画,如果您将来需要,只需调用startAnimating并保持指向UIActivityIndicatorView

的指针

如果您只需要显示一次活动指示器并且不再使用它, Alexanders 答案将最适合您的需求

答案 2 :(得分:0)

使用NSTimer 5秒。 在定时器的回调方法中停止动画

答案 3 :(得分:0)

试试这段代码,

  -(void)viewDidAppear:(BOOL)animated
{
        UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc]     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        activityView.center=self.view.center;
        [self.view addSubview:activityView];
        [activityView startAnimating];
        activityView.tag=1111;
        [activityView release];
}   


    [activityView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:5.0];

    -(void)removeFromSuperview
    {
            UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.viewviewWithTag:1111];
            [activityView stopAnimating];
[activityView removeFromSuperview];
        }