UIImageView Tap Gesture在第二次点击时不工作



我已经在UIImageView上实现了UITapGestureRecognizer,它在第一次点击上工作。在第一次点击,我隐藏的图像和开始动画。一旦动画完成,我再次显示图像。但是,第二次,我没有得到那个UIImageView的Tap事件。

下面是我使用的代码:

- (void)viewDidLoad{
[super viewDidLoad];
defaultDogView= [[UIImageView alloc] initWithFrame:CGRectMake(3, 270, 110, 210)];
[defaultDogView setImage:[UIImage imageNamed:@"dog1.png"]];
defaultDogView.userInteractionEnabled = YES;
[self addGestureRecognizersToPiece:defaultDogView];
[self.view addSubview:defaultDogView];
}
- (void)addGestureRecognizersToPiece:(UIImageView *)piece  
{
NSLog(@"in Gesture");
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapPiece:)];
[tapGesture setDelegate:self];    
[piece addGestureRecognizer:tapGesture];
[tapGesture release];
    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]  initWithTarget:self action:@selector(longPressPiece:)];
    [piece addGestureRecognizer:longPressGesture];
    [longPressGesture release];
    NSLog(@"%@", [piece gestureRecognizers]);
}
- (void)singleTapPiece:(UITapGestureRecognizer *)gestureRecognizer
{
NSLog(@"Image Tapped");
/** Hide the default Image and start the animation ***/
[defaultDogView setHidden:TRUE];
/***Animating the Dog***/
[dogArray addObject:[SpriteHelpers setupAnimatedDog:self.view numFrames:69        withFilePrefix:@"dog" withDuration:(12) ofType:@"png" withValue:0]];
dogView = [dogArray objectAtIndex:0];
[self performSelector:@selector(callBubbleUpdater) withObject:nil afterDelay:5.5];
}
-(void)showDogFrame{
    NSLog(@"%@",[defaultDogView gestureRecognizers]);
    [defaultDogView setHidden:FALSE];
    defaultDogView.userInteractionEnabled = YES;
}

已发现故障。这是因为我的动画视图重叠在UIImageView上。动画完成后我需要做的唯一一件事就是让我的UIImageView zindex为0。我使用下面的代码来解决这个问题:

//animation stuff
//after animation complition
[self.view bringSubviewToFront:bubbleAlphabetView];

最新更新