Shraddha
Shraddha

Reputation: 1052

UIImageView Tap Gesture is not working on second tap

I have implemented UITapGestureRecognizer on UIImageView, It is working on first tap. On First Tap, I am hiding that image and starting animation. Once the animations are completed, i am showing the image again. But, for second time, I am not getting the Tap event of that UIImageView.

Following is the code I am using :

- (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;
}

Upvotes: 2

Views: 2665

Answers (1)

Shraddha
Shraddha

Reputation: 1052

Found the Fault. It was because My Animation View was overlapping over the UIImageView. The Only thing I needed to do after Animation Completion was to make my UIImageView zindex 0. I used the following code to resolve the problem :

//animation stuff

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

Upvotes: 1

Related Questions