我有一个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) {
}];
}