- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一个带有 @property UIActivityIndicatorView* 微调器
的 PhotoViewController
类。 FlickrPhotoViewController
是 PhotoViewController
的子类,它从 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 中显示纺车所使用的方法,并且它始终在那里工作。
如果 UIActivityIndicatorView
存在,您会注意到在 updatePhoto
的开头我会打印一条消息。我在 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
为什么 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
这是我之前期望看到的。尽管如此,我仍然没有得到任何动画。
我已经排除的可能问题:
UIActivityIndicatorView
添加动画 while some expensive method is blocking the main thread .在我的项目中,我所有的文件系统 I/O 和下载方法都在非主 dispatch_async
队列中调用。将 [self.spinner startAnimating];
放入 viewWillAppear
使其在整个下载过程中成功地动画化这一事实排除了所有这三种可能性。
您可以下载this project如果你喜欢。只要转到任何试图显示大照片的屏幕,您就会发现微调器没有出现。这个项目有很多问题,但这是我现在关注的问题。
编辑 1:
编辑 2(2013 年 2 月 2 日):
prepareForSegue
在 FlickrPhotoViewController
。这是否可能导致问题?最佳答案
在你像这样调用 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 - UIActivityIndicatorView 从不设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14631453/
我是一名优秀的程序员,十分优秀!