removeFromSuperview:
が呼び出される前に、animateWithDuration:animations:completion:
を使用して私のユーザーインターフェイスのいくつかの要素(約4要素)を移動しています。アクションを実行する前に、いくつかのブロックが実行を完了したかどうかを知る方法?
私の質問は、removeFromSuperview:
に電話する前に、それらのアニメーションがすべて完了したことをどのように知ることができますか?
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);
を。
これを通常の回答として追加します。 –
ディスパッチキューを作成し、実行中のアニメーションの数だけサスペンドします。スーパービューからの削除を行うブロックをキューに追加します。各アニメーションの完了ブロックで、中断されたキューを再開します。最後のブロックが完了すると、キューに入れられたブロックが実行されます。
いくつかのコードで詳しく説明できますか? – Goles
CATransactionを使用することもできます。埋め込みアニメーションをキャッチします:
[CATransaction begin];
[CATransaction setCompletionBlock:^{ // all animations finished here }];
[UIView animateWithDuration...
[UIView animateWithDuration...
...
[CATransaction commit];
これにより、アニメーションを自分で追跡する必要がなくなります。
複数のブロックを作成するのではなく、アニメーションのセクションですべてを一度にアニメーション化できませんでしたか? –
アニメーションの持続時間とスタイルが異なる場合はありません – Goles
[UIView animateWithDuration呼び出しのネストされたグループに対して単一の完了ブロックを呼び出す方法は?](http://stackoverflow.com/questions/8421441/how-to-invoke -a-single-completion-for-nested-group-of-uiview-animatewith) –