gpt4 book ai didi

iphone - 如何在采取行动之前知道几个区 block 是否已经执行完毕?

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

在调用 removeFromSuperview: 之前,我正在使用 animateWithDuration:animations:completion: 移动我的用户界面的几个元素(大约 4 个元素)。

我的问题是,在调用 removeFromSuperview: 之前我怎么知道所有这些动画已经完成?

最佳答案

好吧,回答我自己的问题。

我最终做了这样的事情:

    // Create dispatch queue & group
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();

// Two group enters
dispatch_group_enter(group);
dispatch_group_enter(group);

// (notice the group parameter in dispatch_group_leave)
[UIView animateWithDuration:0.3 animations:^{
self.pickerView.frame = CGRectMake( self.pickerView.frame.origin.x
, self.view.bounds.size.height + self.pickerView.frame.size.height/2
, self.pickerView.frame.size.width
, self.pickerView.frame.size.height);
} completion:^(BOOL finished){
dispatch_group_leave(group);
}];


[UIView animateWithDuration:0.3 animations:^{
self.navigationBar.frame = CGRectMake( self.navigationBar.frame.origin.x
, -self.navigationBar.frame.size.height
, self.navigationBar.frame.size.width
, self.navigationBar.frame.size.height);
} completion:^(BOOL finished){
dispatch_group_leave(group);
}];

// Finishing callback
dispatch_group_notify(group, queue, ^{
[self.view removeFromSuperview];
});

// Release the group
dispatch_release(group);

我希望这可以作为其他人的榜样。

关于iphone - 如何在采取行动之前知道几个区 block 是否已经执行完毕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11768527/

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