确定。所以我试图在转换到下一个视图控制器之前使用GCD处理所有重载。我打开大型档案文件并提取它们需要一些时间。
整个过程是这样的:
单击UICollectionViewCell>显示活动指示符>让GCD使用performSelector处理重载>调用转换选择器:onThread:.....
问题是当我使用mainThread时,过渡发生得太快并且所有的加载都没有生效,直到一段时间后转换看起来很糟糕并且在使用currentThread时,它只需要花费很多时间,它看起来很糟糕的应用程序。
-(void)someMethod
{
//activity Indicator before transition begins
UIActivityIndicatorView *activity=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activity setFrame:self.view.bounds];
[self.view addSubview:activity];
[self.view bringSubviewToFront:activity];
activity.hidesWhenStopped=YES;
[activity startAnimating];
dispatch_queue_t transitionQueue;
transitionQueue = dispatch_queue_create("com.app.transitionQueue", NULL);
dispatch_async(transitionQueue,^{
//heavy lifting code
viewerPVC=.....
dispatch_async(dispatch_get_main_queue(),^{
[activity stopAnimating];
[self transitionToMangaViewer:mReaderPVC];
});
};
}
-(void)transitionToViewer:(ViewerPVC*)viewerPVC
{
[self.navigationController pushViewController:mReaderPVC animated:YES];
}
所以尝试了第一个建议,但由于CollectionViewController在转换后的一段时间内仍然保留在背景上,因此过渡仍然看起来有些错误
答案 0 :(得分:2)
当你使用gcd时,你不需要使用NSThread,尝试这样的事情
int c = 0;
答案 1 :(得分:1)
UI更新应该在主线程上完成,无需创建新线程来执行UI转换。请尝试以下代码:
dispatch_async(transitionQueue,^{
//heavy lifting code
viewerPVC=.....
dispatch_async(dispatch_get_main_queue(), ^{
[activity stopAnimating];
[self performSelector:@selector(transitionToAnotherViewer:) withObject:viewerPVC waitUntilDone:YES];
});
};