gpt4 book ai didi

ios - UIActivityIndi​​catorView 从不设置动画

转载 作者:可可西里 更新时间:2023-11-01 06:10:48 25 4
gpt4 key购买 nike

我有一个带有 @property UIActivityIndi​​catorView* 微调器PhotoViewController 类。 FlickrPhotoViewControllerPhotoViewController 的子类,它从 Flickr 下载照片并告诉微调器何时开始和停止动画。每次为 View Controller 提供 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
}
});
});
}

上述方法正是我在下载表格内容时在我的表格 View Controller 中显示纺车所使用的方法,并且它始终在那里工作。

如果 UIActivityIndi​​catorView 存在,您会注意到在 updatePhoto 的开头我会打印一条消息。我在 awakeFromNibviewDidLoadviewWillAppear 中放置了类似的语句。当我运行它时,这是我得到的确切输出:

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

为什么 spinner 不存在于 awakeFromNib 中?文档指出“当一个对象收到一条 awakeFromNib 消息时,它保证已经建立了所有的导出和 Action 连接。” IBOutlet 是否可以在它所连接的对象不存在的情况下进行连接?在这种情况下,spinner IBOutlet 是否可以在不分配 spinner 的情况下连接到 Storyboard?

除此之外,我覆盖了 spinner 的 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

这是我之前期望看到的。尽管如此,我仍然没有得到任何动画。

我已经排除的可能问题:

[self.spinner startAnimating]; 放入 viewWillAppear 使其在整个下载过程中成功地动画化这一事实排除了所有这三种可能性。

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

编辑 1:

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

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

  • 由于另一个 View Controller 的 prepareForSegueFlickrPhotoViewController。这是否可能导致问题?

最佳答案

在你像这样调用 updatePoto 方法之前尝试启动动画 uiactivityindictor真正调用它而不是调用 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 - UIActivityIndi​​catorView 从不设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14631453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com