あなたが話していることは、セマフォにぴったりのように聞こえます(ディスパッチセマフォを使用して有限リソースの使用を規制するという見出しの下を参照してください)!UIView
リンク先の SO Answer を見ましたが、アニメーションのケースは解決しないと思います。セマフォの使用方法は次のとおりです。
ビュー コントローラーでインスタンス変数を追加し、メソッドdispatch_semaphore_t _animationSemaphore;
で初期化します。- init
- (id)init
{
if ((self = [super init])) {
_animationSemaphore = dispatch_semaphore_create(1);
}
return self;
}
- dealloc
(を使用してメソッド内のセマフォを解放することを忘れないでくださいdispatch_release
。また、 を使用してキューに入れられたアニメーションが終了するのを待ちたいと思うかもしれませんがdispatch_semaphore_wait
、それはあなたが理解できるように残しておきます。)
アニメーションをキューに入れたいときは、次のようにします。
- (void)animateSomething
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
dispatch_semaphore_wait(_animationSemaphore, DISPATCH_TIME_FOREVER);
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.5 animations:^{
// Your fancy animation code
} completion:^(BOOL finished) {
dispatch_semaphore_signal(_animationSemaphore);
}];
});
});
}
テンプレートを使用して、や- animateSomething
を表示するなど、さまざまなことを実行できます。SSHUDView
UIAlertView