且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

显示微调器并将其移除到同一个块中

更新时间:2023-11-10 07:51:21

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