gpt4 book ai didi

ios - 显示微调器并在同一 block 中将其删除

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

在一个可能需要几秒钟的方法中,我有:

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];

微调器没有显示。可能是因为当时屏幕没有更新。我怎样才能解决这个问题?

最佳答案

使用 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];
});
});

关于ios - 显示微调器并在同一 block 中将其删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16529914/

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