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) {
}];
}