2

UIImageViewアニメーションループにあるがあります。触れられたかどうかを検出し、でメッセージを出力したいNSLog。触ったら別のアニメーションを実行するという発想ですが、そもそも触ったかどうかは今のところわかりません。ユーザーインタラクションが有効になりました。コードは次のとおりです。

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    UIView *touchedView = [touch view];
    if (touchedView == imgSun) {
        NSLog(@"Sun touched");
        [self spinSun];
    } else if (touchedView == imgBee) {
        NSLog(@"Bee touched");
    } else if (touchedView == imgClouds) {
        NSLog(@"Clouds touched");
    }
}

アニメーションの方法:

-(void) beeBobbing
{
    [UIView animateWithDuration:1.0f delay:0 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat) animations:^{
        CGPoint bottomPoint = CGPointMake(215.0, 380.0);
        imgBee.center = bottomPoint;
    } completion:^(BOOL finished) {

    }];    
}
4

1 に答える 1

2

これはおそらく、アニメーション中にユーザー統合がデフォルトで無効になっているためです。

animateWithDuration:delay:options:animations:completion: ドキュメントを参照してください:

アニメーション中は、アニメーション中のビューに対するユーザー操作が一時的に無効になります。(iOS 5 より前では、ユーザーの操作はアプリケーション全体で無効になっています。) ユーザーがビューを操作できるようにする場合は、options パラメーターに UIViewAnimationOptionAllowUserInteraction 定数を含めます。

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html 1

メソッド「beeBobbing」のオプションに渡される値に UIViewAnimationOptionAllowUserInteraction を追加するだけでよいでしょう。

于 2012-05-14T13:14:05.873 に答える