gpt4 book ai didi

ios - Objective-c 方法队列

转载 作者:行者123 更新时间:2023-11-29 02:37:24 24 4
gpt4 key购买 nike

我有一个可以创建 View 并为其设置动画的方法

- (void) draw {
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(57, 353, 350, 80)];
[self.view addSubview:label];

[UIView animateWithDuration:3
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
[UIView animateWithDuration:2
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
label.alpha = 0;
} completion:^(BOOL finished) {
[self.view willRemoveSubview:label];
}];
} completion:^(BOOL finished) {
}];

单击按钮时调用此方法。但是,如果我快速单击,新 View 就会出现,而无需等待前一个 View 完成。我想创建一个方法队列,例如,当我点击按钮时,新事件将被推送到队列中,并且所有事件都在等待前一个事件完成后才能开始。也许我可以使用 NSOperationQueue 或 GCD 来做到这一点?

最佳答案

如前所述,嵌套的 animateWithDuration: 是怎么回事。此外,更重要的是,您可能不想对 NSOperationQueue 或 GCD 做任何事情,因为所有动画都必须在主线程上完成。如果你真的想做一些线程你最终会得到类似的东西

-(void)draw
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
dispatch_sync(dispatch_get_main_queuem ^{
//do your animations and pray you don't cause deadlock
}
}
}

您可能应该做的是在按下按钮时禁用它,然后在动画的完成 block 中重新启用它

关于ios - Objective-c 方法队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26192979/

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