为什么我的UIActivityIndi​​catorView停止动画? [英] Why won't my UIActivityIndicatorView stop animating?

查看:97
本文介绍了为什么我的UIActivityIndi​​catorView停止动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的应用程式代表管理活动指标,这样我的任何观点都可以把指标。所以,我添加它作为一个子视图到窗口和开始/停止如下:

I am trying to manage the activity indicator from my App Delegate, that way any of my views can put the indicator up. So, I am adding it as a subview to 'window' and start/stop as follows:

- (void)didStartActivity
{
    if( activityIndicator == nil ) {
        activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        activityIndicator.hidesWhenStopped = YES;
        activityIndicator.center = window.center;
        activityIndicator.transform = CGAffineTransformScale(CGAffineTransformIdentity, 6.0, 6.0);
    }
    NSLog(@"%s: starting the activityIndicator", __FUNCTION__);
    [window addSubview:activityIndicator];
    [activityIndicator startAnimating];
}



我看到日志消息,所以我知道代码正在被调用。指示器位于中央,是默认大小的6倍。但是,stopAnimating不停止。我只能得出结论是,它需要在当前视图控制器中运行。

I see the log messages, so I know the code is being invoked. The indicator is at the center and 6x the default size. However, the stopAnimating isn't stopping. The only thing I can conclude is that it needs to run in the present view controller.

- (void)didStopActivity
{
    NSLog(@"%s: stopping the activityIndicator", __FUNCTION__);
    [activityIndicator stopAnimating];
    [activityIndicator removeFromSuperview];
}


推荐答案

我做了我的实验,并且确定,当我添加活动指示器作为viewcontroller的视图的子视图时,它工作完美无瑕。然而,当我然后使用这个新的simpleton项目,尝试它作为一个子视窗,它也工作。显然,我的代码中有一个错误,需要更多的检查。

OK. I did my experiment and sure enough, it worked flawlessly when I added the activity indicator as a subview of viewcontroller's view. However, when I then used that new simpleton project to try it as a subview to window it also worked. Obviously a bug in my code and it needs more inspection.

我将授予Eimantas的答案,因为调试的概念在我的解决方案是有帮助的。

I will award both Eimantas with the answer as the debug notion was helpful in my solution.

这篇关于为什么我的UIActivityIndi​​catorView停止动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆