2011-01-17 15 views
7

こんにちは、タッチイベントに応答して、私のアプリケーションはアニメーションを表示します。現在のアニメーションが起きている間でも、ユーザーが本当に速く、別のタッチをしていると、すべてがうんざりしてしまいます。UIViewアニメーションの同期

フレームワークによって提供されるこの問題を処理する標準的な方法はありますか?あるいは私は間違った方法でアニメーションをやっていますか?

現在、これを処理するためにフラグ(animationInProgress)をチェックしていますが、これが私たちがこれに頼らなければならないものかどうかを知りたがっていますか?ここで

コードは次のとおりです。あなたはそれがしたい場合は、同時に起こるために何かをできるように、気づいたとして

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
    NSMutableArray *c = (NSMutableArray*)context; 
    UINavigationController *nc = [c objectAtIndex:0]; 
    [nc.view removeFromSuperview]; 
    animationInProgress = NO; 
} 

- (void)transitionViews:(BOOL)topToBottom { 
    if (animationInProgress) { 
     return; 
    } 
    animationInProgress = YES; 
    NSMutableArray *context = [[NSMutableArray alloc] init]; 
    [UIView beginAnimations:@"myanim" context:context]; 
    [UIView setAnimationDuration:0.7f]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 

    UIViewController *from; 
    UIViewController *to; 
    if (navController3.view.superview == nil) { 
     from = navController2; 
     to = navController3; 
    } else { 
     from = navController3; 
     to = navController2; 
    } 

    int height; 
    if (topToBottom) { 
     height = -1 * from.view.bounds.size.height; 
    } else { 
     height = from.view.bounds.size.height; 
    } 

    CGAffineTransform transform = from.view.transform; 

    [UIView setAnimationsEnabled:NO]; 
    to.view.bounds = from.view.layer.bounds; 
    to.view.transform = CGAffineTransformTranslate(transform, 0, height); 
    [window addSubview:to.view]; 

    [UIView setAnimationsEnabled:YES]; 
    from.view.transform = CGAffineTransformTranslate(from.view.transform, 0, -1 * height); 
    to.view.transform = transform; 

    [context addObject:from]; 

    [UIView commitAnimations]; 

    return; 
} 

答えて

10

フレームワークのデフォルトの動作は、あります。

あなたが行っているようなフラグを使用することは、特定のアニメーションが既に実行中であることを阻止することが目的であれば、完全に合理的です。

あなたは概念的に「レベルアップ」に行くと、あなたが使用することができ、アニメーション中のすべてのアプリケーションに入るのいずれかのタッチイベントを停止する場合:

とペア
[[UIApplication sharedApplication] beginIgnoringInteractionEvents]; 

[[UIApplication sharedApplication] endIgnoringInteractionEvents]; 
+0

begin/endIgnoringInteractionEventsを使用してアニメーション中にタッチイベントがアプリケーションに入力されないようにすると、このブロックに入っているタッチイベントはどうなりますか? endIgnoringInteractionEventsが呼び出されるか、(名前が示すように)すべてのタッチを捨てると、それらはキャッシュされてアプリケーションに提示されますか? – vance

+0

@vance:名前が示すように、それらは捨てられます。 –

関連する問題