4

全部

我正在尝试UIActivityIndicator在方法上运行 5 秒viewdidappear。但是我如何为活动指示器(5 秒)设置时间限制?

这是代码UIActivityIndicator

 UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc]     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    activityView.center=self.view.center;

    [activityView startAnimating];

    [self.view addSubview:activityView];
4

4 回答 4

5

一行,没有额外的依赖和条件:

[activityView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:5.0];
于 2013-05-31T09:33:14.427 回答
4

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

activityView.hidesWhenStopped = YES;

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

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

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

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

于 2013-05-31T09:34:24.920 回答
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];
        }
于 2013-05-31T10:26:55.867 回答
0

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

于 2013-05-31T09:33:42.807 回答