gpt4 book ai didi

ios - dispatch_sync 阻止我的 UI,我无法单击任何按钮

转载 作者:行者123 更新时间:2023-11-29 03:53:52 26 4
gpt4 key购买 nike

我有两个带有dispatch_sync的 block ,当第一个 block 结束时,我向用户显示窗口并开始运行第二个 block 。但在第二个 block 结束之前我不会单击屏幕上的任何按钮..

看代码:

[HUD showUIBlockingIndicatorWithText:@"Loading..."];
dispatch_queue_t queue = dispatch_queue_create("myQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^ {
dispatch_sync(dispatch_get_main_queue(), ^{
[UIView beginAnimations:@"fade" context:nil];
[UIView setAnimationDuration:0.5];
self.capa.alpha = 0.0;
[UIView commitAnimations];
[HUD hideUIBlockingIndicator];
});
});

dispatch_barrier_async(queue, ^ {
//code executed in the background
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"entrou na foto");
//[self getFotos];
});
});

最佳答案

如果您在主线程上调用任何代码,它都会阻塞您的 UI,因此调用

dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"entrou na foto");
[self getFotos];
});

将阻止您的 UI,直到 [self getFotos] 返回。

关于ios - dispatch_sync 阻止我的 UI,我无法单击任何按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16753414/

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