显示微调器并将其移除到同一个块中 [英] show spinner and remove it in the same block
本文介绍了显示微调器并将其移除到同一个块中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个可能需要几秒钟的方法中我有:
In a method that can take up to several seconds i have:
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(135,140,50,50)];
spinner.color = [UIColor blueColor];
[spinner startAnimating];
[_mapViewController.view addSubview:spinner];
// lots of code
[spinner removeFromSuperview];
微调器没有出现。可能是因为当时屏幕没有更新。
如何解决这个问题?
The spinner doesn't show up. Probably since the screen doesn't get update at that time. How can i get around this problem?
推荐答案
使用GCD:
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(135,140,50,50)];
spinner.color = [UIColor blueColor];
[spinner startAnimating];
[_mapViewController.view addSubview:spinner];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// lots of code run in the background
dispatch_async(dispatch_get_main_queue(), ^{
// stop and remove the spinner on the main thread when done
[spinner removeFromSuperview];
});
});
这篇关于显示微调器并将其移除到同一个块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文