ios – UIActivityIndi​​catorView永远不会动画

前端之家收集整理的这篇文章主要介绍了ios – UIActivityIndi​​catorView永远不会动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个带有@property UIActivityIndi​​catorView *微调器的PhotoViewController类. FlickrPhotoViewController是PhotoViewController的子类,它从Flickr下载照片并告诉微调器何时开始和停止动画.每次为视图控制器提供Flickr照片时,都会调用“updatePhoto”:

- (void)updatePhoto { // Download photo and set it
    NSLog("updatePhoto called");
    if (self.spinner) NSLog(@"Spinner exists in updatePhoto");
    dispatch_queue_t downloadQueue = dispatch_queue_create("downloader",NULL);
    [self.spinner startAnimating];

    dispatch_async(downloadQueue,^{
        // Download the photo
        dispatch_async(dispatch_get_main_queue(),^{
            [self.spinner stopAnimating];
            // Set the photo in the UI
            }
        });
    });
}

上面的方法正是我用来在表格视图控制器中显示旋转轮的同时表格内容下载,它总是在那里工作.

您会注意到在updatePhoto的开头,如果UIActivityIndi​​catorView存在,我会打印一条消息.我在awakeFromNib,viewDidLoad和viewWillAppear中添加了类似的语句.当我运行它时,这是我得到的确切输出

2013-01-31 21:30:55.211 FlickrExplorer[1878:c07] updatePhoto called
2013-01-31 21:30:55.222 FlickrExplorer[1878:c07] Spinner exists in viewDidLoad
2013-01-31 21:30:55.223 FlickrExplorer[1878:c07] Spinner exists in viewWillAppear

为什么awakeFromNib中不存在微调器?文档表明“当一个对象收到一个awakeFromNib消息时,它保证已经建立了所有的插座和动作连接.” IBOutlet可以连接而不存在它连接的对象吗?在这种情况下,微调器IBOutlet是否可以连接到故事板而不分配微调器?

除此之外,我覆盖了微调器的getter,以便在它不存在时进行实例化.结果,打印输出现在看起来像这样:

2013-01-31 21:48:45.646 FlickrExplorer[2222:c07] Spinner exists in awakeFromNib
2013-01-31 21:48:45.647 FlickrExplorer[2222:c07] updatePhoto called
2013-01-31 21:48:45.647 FlickrExplorer[2222:c07] Spinner exists in updatePhoto
2013-01-31 21:48:45.649 FlickrExplorer[2222:c07] Spinner exists in viewDidLoad
2013-01-31 21:48:45.650 FlickrExplorer[2222:c07] Spinner exists in viewWillAppear

这是我原本预期会看到的.尽管如此,我仍然没有得到任何动画.

我排除的可能问题:

> spinner is the same color as the background,让它看不见.在我的项目中,背景为黑色,微调器为白色.
>我正在尝试为UIActivityIndi​​catorView while some expensive method is blocking the main thread设置动画.在我的项目中,我的所有文件系统I / O和下载方法都在非主dispatch_async队列中调用.
>旋转器的@L_404_2@.在我的项目中,我已经多次检查过这次.从故事板和PhotoViewController.h文件中可以看到它已连接.

所有这三种可能性都被放入[self.spinner startAnimating];在viewWillAppear中,它使整个下载过程成功动画.

如果你愿意,可以下载this project.只需转到任何试图显示大照片的屏幕,您就会看到微调器没有出现.这个项目有很多问题,但这是我现在关注的问题.

编辑1:

>我在Git上添加了项目缺少的依赖项,因此项目将会
现在为你编译

编辑2(2013年2月2日):

>由于另一个视图控制器的prepareForSegue在FlickrPhotoViewController中设置了照片,因此我在调用updatePhoto方法时仅在iPhone上看到此问题.这有可能导致这个问题吗?

解决方法

在你调用像这样的updatePoto方法之前尝试触发启动uiactivityindictor的动画
Tru称之为完全调用UpdatePhoto的全部内容

[self startAnimatingAndThenUpdatePhoto];


-(void)startAnimatingAndThenUpdatePhoto{
 if (self.spinner) NSLog(@"Spinner exists in updatePhoto");
  [self.spinner startAnimating];
 [self performSelector:@selector(updatePhoto) withObject:nil afterDelay:0.01];
}
 - (void)updatePhoto { // Download photo and set it
        NSLog("updatePhoto called");
        dispatch_queue_t downloadQueue = dispatch_queue_create("downloader",NULL);

        dispatch_async(downloadQueue,^{
            // Download the photo
            dispatch_async(dispatch_get_main_queue(),^{
                [self.spinner stopAnimating];
                // Set the photo in the UI
                }
            });
        });
    }

这不是世界上最好的方法,但它会做出工作

猜你在找的iOS相关文章