Iphone 检测是否触摸了移动的UIImageView

Iphone 检测是否触摸了移动的UIImageView,iphone,ios,uiimageview,touchesbegan,Iphone,Ios,Uiimageview,Touchesbegan,我有一个UIImageView,它位于动画循环中。我想检测它是否被触摸,并用NSLog打印一条消息。我们的想法是,如果它被触摸过,则执行另一个动画,但目前我无法检测它是否被触摸过。已启用用户交互。代码如下: -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; UIView *touchedView = [touch view

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

    }];    
}

这可能是因为在动画期间默认情况下禁用了用户集成

请参见动画持续时间:延迟:选项:动画:完成:文档:

在动画期间,将暂时禁用正在设置动画的视图的用户交互。(在iOS 5之前,对整个应用程序禁用用户交互。)如果希望用户能够与视图交互,请在选项参数中包含UIViewAnimationOptionAllowUserInteraction常量


您可以将UIViewAnimationOptionAllowUserInteraction添加到方法“Beebobing”中传递给选项的值中。

是否对UIImageView进行子类化?因为否则您无法访问touchesbented委托方法。还有,为什么不简单地使用UIgestureRecogizers呢?另一种方法是使用自定义按钮并将图像作为该按钮的背景图像,这样你就可以很容易地理解它是否被触摸了。我对编程非常陌生,以前从未使用过UIgestureRecogisers。在使用了beofre之后,我决定这样做。下面的答案似乎对你有用me@garethdn:如果J_D的答案有效,你应该接受它——而且应该有效:)