Tap gesture is not working on UIimageview - iphone

In my application i have three uiimageview which is moving randomly. on single tap on imageview it should hide. But my tapgesture is not working. on single tap it is not getting hide.
- (void)showAlert1:(UITapGestureRecognizer *)sender
{
if (image1.tag == 1)
{
image1.hidden = TRUE;
}
else
{
image1.hidden = FALSE;
}
}
- (void)showAlert2:(UITapGestureRecognizer *)sender
{
if (image1.hidden == TRUE && image3.hidden == FALSE)
{
image2.hidden = TRUE;
}
else
{
image2.hidden = FALSE;
}
}
- (void)showAlert3:(UITapGestureRecognizer *)sender
{
if (image1.hidden == TRUE && image2.hidden == TRUE)
{
image3.hidden = TRUE;
}
else
{
image3.hidden = FALSE;
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (image1.tag == 1)
{
image1.userInteractionEnabled = YES;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTargetelf actionselector(imageAlerts];
tap.numberOfTapsRequired = 1;
[image1 addGestureRecognizer:tap];
}
if (image2.tag == 2)
{
image2.userInteractionEnabled = YES;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTargetelf actionselector(showAlert2];
tap.numberOfTapsRequired = 1;
[image2 addGestureRecognizer:tap];
}
if (image3.tag == 3)
{
image3.userInteractionEnabled = YES;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTargetelf actionselector(showAlert3];
tap.numberOfTapsRequired = 1;
[image3 addGestureRecognizer:tap];
}
}
Can anyone help me?
Thanks in advance

Please checkmark the userInteractionEnabled and multipleTouch in xib file if you have added image in xib
or
image.userInteractionEnabled = YES;
image.multipleTouchEnabled = YES;
in ViewDidLoad

Did you implement UIGestureRecognizerDelegate and set in to self?

try this -
- (void)viewWillAppearBOOL:animated
{
[super viewWillAppear:animated];
if (image1.tag==1)
{
image1.userInteractionEnabled = YES;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTargetelf actionselector(showAlert1:];
tap.numberOfTapsRequired = 1;
[image1 addGestureRecognizer:tap];
}
if (image2.tag==2)
{
image2.userInteractionEnabled = YES;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTargetelf actionselector(showAlert2:];
tap.numberOfTapsRequired = 1;
[image2 addGestureRecognizer:tap];
}
if (image3.tag==3)
{
image3.userInteractionEnabled = YES;
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTargetelf actionselector(showAlert3:];
tap.numberOfTapsRequired = 1;
[image3 addGestureRecognizer:tap];
}
}
Also it has memory leak. UIGesture is not released after it adds to image.

Try this
- (void)showAlert1:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{
// your handling code
if (image1.tag==1)
image1.hidden=TRUE;
else
image1.hidden=FALSE;
}
}

Related

tapGesture is not working for labels

UITapGestureRecognizer *tapGesture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(openNewView:)];
UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(openNewView:)];
[writeReview_view setTag:1];
[map_view setTag:2];
[writeReview_view addGestureRecognizer:tapGesture1];
[map_view addGestureRecognizer:tapGesture2];
-(void)openNewView:(UITapGestureRecognizer *)recog1
{
NSLog( #"recog1.view.tag == %d",recog1.view.tag);
if (recog1.view.tag==2)
{
[self performSegueWithIdentifier:#"mapsegue" sender:self];
}
else
{
[self performSegueWithIdentifier:#"loginsegue" sender:self];
}
}
Enable userInteractionEnabled on the label
label.userInteractionEnabled = YES;

Is there a way to detect multiple pan gestures?

I want the user to be able to pan from each thumb simultaneously but I can't figure out how to detect it with uigesturerecognizer. I can detect a tap and a pan simultaneously no problem.
It appears that the second pan will block the first.
Any help is appreciated.
I solved it by defining shouldReceiveTouch like so:
-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (gestureRecognizer == singleTap) {
return YES;
}
if (gestureRecognizer == pan1 && [touch locationInView:self].x > 160) {
return YES;
}
if (gestureRecognizer == pan2 && [touch locationInView:self].x <= 160) {
return YES;
}
return FALSE;
}
And initWithFrame has the following code:
self.userInteractionEnabled = YES;
singleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:#selector(handleSingleTap:)];
singleTap.numberOfTapsRequired = 1;
[self addGestureRecognizer:singleTap];
[singleTap release];
NSLog(#"tap: %p", singleTap);
pan1 = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:#selector(handlePan1:)];
[self addGestureRecognizer:pan1];
NSLog(#"pan1: %p", pan1);
pan2 = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:#selector(handlePan2:)];
[self addGestureRecognizer:pan2];
for (UIGestureRecognizer *recognizer in self.gestureRecognizers) {
recognizer.delegate = self;
}
NSLog(#"pan2: %p", pan2);

Sequence Animation using NSTimer

good day.. I have this code.. and this two is for actionAnimating Button and stopAnimating Button..I just want to know if how to make those two button integrate in ONE button.. for example.. I click the button then it animates.. when I click again that actionAnimating Button, i want to cancel/stop the animation at the same time i want to play/animate again.. in short i want to cancel the animation when i click again the actionAnimating button..
-(void)flowerAnimationSequence//START ANIMATION
{
MotherView.alpha = 0;
flower.alpha = 0;
[animationContainer1 removeFromSuperview];
actselected = YES;
NSLog(#"start");
if (((sequenceAnimateCounter == 0) || (sequenceAnimateCounter==1)) && (actselected = YES))
{
aImageViewSlideShow = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
aImageViewSlideShow.tag = 171;
[self.view addSubview:aImageViewSlideShow];
}
if (sequenceAnimateCounter < 183)
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.035 target:self selector:#selector(flowerAnimationSequence) userInfo:nil repeats:NO];
}
else if (sequenceAnimateCounter ==183)
{
aImageView = (UIImageView *)[self.view viewWithTag:171];
NSLog(#"done");
actselected = NO;
sequenceAnimateCounter = 0;
[aImageView removeFromSuperview];
aImageView = nil;
[self DefaultPosition];
}
aImageView = (UIImageView *)[self.view viewWithTag:171];
NSString *aStrNumber = [NSString stringWithFormat:#"%i",sequenceAnimateCounter];
NSString *aBundlePath = [[NSBundle mainBundle]bundlePath];
NSString *aImagePath = [NSString stringWithFormat:#"%#/sapatos_%#.png",aBundlePath,aStrNumber];
[aImageView setImage:[UIImage imageWithContentsOfFile:aImagePath]];
[self.view bringSubviewToFront: aImageView];
sequenceAnimateCounter = sequenceAnimateCounter+1;
if (sequenceAnimateCounter == 1)
{
[aImageView removeFromSuperview];
}
}
-(void)stopanim//STOP BUTTON
{
[timer invalidate];
sequenceAnimateCounter =0;
NSLog(#"stop");
[aImageView removeFromSuperview];
}
thanks in advance!
Hm...
you want to start/stop in one button?
BOOL isAnimating = NO;
- (void)startStopAnimating
{
if (!isAnimating) {
isAnimating = YES
// start animation
} else {
isAnimating = NO;
// stop animation
}
}

How to use UISwipeGestureRecognizer on UIButton?

I have a UIbutton which i want to work as a joystick. So i am trying to add some gesture recognizer on the same button.
I have this in my code right now:
#implementation CUETutorialSixteenClusterRootController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:#"CUETutorialLandscapeClusterRootController" bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (id)init {
self = [super init];
if (self) {
_leftInActiveView = [[NSMutableArray alloc] init];
_rightInActiveViews = [[NSMutableArray alloc] init];
_centerInActiveViews = [[NSMutableArray alloc]init];
_centerActiveViews = [[NSMutableArray alloc]init];
UIImageView * inActLeftView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 82, 98)] autorelease];
inActLeftView.image = [UIImage imageNamed:#"1-am-station_01.png"];
[_leftInActiveView addObject:inActLeftView];
UIImageView * inActRightView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 82, 98)] autorelease];
inActRightView.image = [UIImage imageNamed:#"1-am-station_03.png"];
[_rightInActiveViews addObject:inActRightView];
NSArray * imagesName = [NSArray arrayWithObjects:[UIImage imageNamed:#"1_start.png"],
[UIImage imageNamed:#"2_apptray_audio_selected.png"],
[UIImage imageNamed:#"2_apptray_phone_selected.png"],
[UIImage imageNamed:#"4_phonemenu_contacts_highlighted.png"],
[UIImage imageNamed:#"5_phonemenu_recentcalls_highlighted.png"],
[UIImage imageNamed:#"6_recent_calls.png"],
[UIImage imageNamed:#"7_bottom_hit.png"],
[UIImage imageNamed:#"8_recent_call_details.png"],
[UIImage imageNamed:#"9_calling.png"],
[UIImage imageNamed:#"9_calling_myphone.png"],
[UIImage imageNamed:#"9_call_ended.png"],nil];
NSLog(#"Count:%d",[imagesName count]);
for (int i =0; i<11; i++) {
UIImageView * inActCenterView = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 226, 98)] autorelease];
inActCenterView.image = [imagesName objectAtIndex:i];
[_centerActiveViews addObject:inActCenterView];
[_centerInActiveViews addObject:inActCenterView];
}
}
return self;
}
-(void)showClusterType:(clusterType)cluster{
switch (cluster) {
//Base Cluster is analog
case kClusterTypeBase:
{
[self.fullClusterContainerView removeFromSuperview];
[self.view addSubview:self.baseClusterContainerView];
[self.view addSubview:self.baseClusterImageView];
CUETutorialSixteenAplicationHomeScreen * clusAppScreen = [[CUETutorialSixteenAplicationHomeScreen alloc] initWithDelegate:self];
clusAppScreen.dataSource = self;
clusAppScreen.rootController = self;
self.clusterHomeScreen = clusAppScreen;
[self.baseClusterContainerView addSubview:clusAppScreen.view];
[clusAppScreen release];
/*
[self.view bringSubviewToFront:self.steeringWheelImageView];
[self.view bringSubviewToFront:self.promptLabel];
[self.view bringSubviewToFront:[self.view viewWithTag:kFavDownButton]];
[self.view bringSubviewToFront:[self.view viewWithTag:kFavUpButton]];
[self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonUp]];
[self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonLeft]];
[self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonRight]];
[self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonDown]];
[self.view bringSubviewToFront:[self.view viewWithTag:kRightButtonCenter]];
*/
[self.view bringSubviewToFront:self.promptLabel];
}
break;
//Full cluster is digital
case kClusterTypeFull:
{
[self.baseClusterImageView removeFromSuperview];
[self.baseClusterContainerView removeFromSuperview];
[self.view addSubview:self.fullClusterContainerView];
}
break;
default:
break;
}
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
_step =1;
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[self.gestureRecieverButton addGestureRecognizer:recognizer];
[recognizer release];
recognizer = nil;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
[self.gestureRecieverButton addGestureRecognizer:recognizer];
[recognizer release];
recognizer = nil;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.gestureRecieverButton addGestureRecognizer:recognizer];
[recognizer release];
recognizer = nil;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.gestureRecieverButton addGestureRecognizer:recognizer];
[recognizer release];
recognizer = nil;
}
- (void)viewDidUnload
{
[super viewDidUnload];
time=0;
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(void)dealloc{
[super dealloc];
[_leftInActiveView release];
[_rightInActiveViews release];
[_centerActiveViews release];
[_centerInActiveViews release];
}
-(void)animateToView:(UIView *)aview{
if(aview){
//CGRect rect = [aview convertRect:aview.bounds toView:self.view];
CGRect rect = aview.frame;
[self animateHandFromRect:self.promptLabel.frame toRect:rect];
}
else{
[self animateHandToNSValueRect:nil];
}
}
-(void)finishTutorial{
[self displayPromptText:#"TUTORIAL COMPLETE"];
[self displayNavigationBarWithTitle:#"TUTORIAL COMPLETE"];
[self performBlock:^{
[self.clusterHomeScreen.view removeFromSuperview];
[self showScoresScreen];
}afterDelay:1];
}
-(void)animateHandToCenterButton
{
[self displayPromptText:#"TAP RIGHT SIDE CENTER BUTTON"];
[self displayNavigationBarWithTitle:#"TAP RIGHT SIDE CENTER BUTTON"];
[self animateToView:self.rCenterButton];
}
-(void)animateHandToDownButton {
[self displayPromptText:#"TAP RIGHT SIDE DOWN BUTTON"];
[self displayNavigationBarWithTitle:#"TAP RIGHT SIDE DOWN BUTTON"];
[self animateToView:self.rDownButton];
}
-(void)animateHandToUpButton{
[self displayPromptText:#"TAP RIGHT SIDE UP BUTTON"];
[self displayNavigationBarWithTitle:#"TAP RIGHT SIDE UP BUTTON"];
[self animateToView:self.rUpButton];
}
-(void)replaceCallScreen{
[self performBlock:^{
[self pressedRightButtonCenter];
} afterDelay:2.0];
}
-(void)changeTimer {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(startTicking) userInfo:nil repeats:YES];
}
-(void)startTicking {
time = time +1;
self.clusterHomeScreen.callTimer.text = [NSString stringWithFormat:#"00:0%d",time];
if (time==9) {
[timer invalidate];
}
}
-(void) animateHandToVolUpButton {
[self displayPromptText:#"TAP VOLUME UP BUTTON"];
[self displayNavigationBarWithTitle:#"TAP VOLUME UP BUTTON"];
[self animateToView:self.rVolUpButton];
}
-(void) animateHandToVolDownButton {
[self displayPromptText:#"TAP VOLUME DOWN BUTTON"];
[self displayNavigationBarWithTitle:#"TAP VOLUME DOWN BUTTON"];
[self animateToView:self.rVolDownButton];
}
-(void)removeVolumeView {
[self pressedRightButtonCenter];
[self.clusterHomeScreen runNextStep];
}
-(void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"Swipe received.%#",recognizer);
}
-(IBAction)buttonClicked:(id)sender
{
if ([sender tag]==kRightButtonDown && _step ==1)
{
[self pressedRightButtonDown];
[self displayPromptText:#"TAP AGAIN"];
[self displayNavigationBarWithTitle:#"TAP AGAIN"];
_step++;
}
else if ([sender tag]==kRightButtonDown && _step == 2)
{
[self pressedRightButtonDown];
[self animateToView:self.rCenterButton];
[self displayPromptText:#"TAP CENTER BUTTON"];
[self displayNavigationBarWithTitle:#"TAP CENTER BUTTON"];
_step++;
}
else if ([sender tag]==kRightButtonCenter && _step == 3)
{
[self pressedRightButtonCenter];
[self animateToView:self.rUpButton];
_step++;
}
else if ([sender tag]==kRightButtonUp && _step == 4)
{
[self pressedRightButtonUp];
[self displayPromptText:#"TAP CENTER BUTTON"];
[self displayNavigationBarWithTitle:#"TAP CENTER BUTTON"];
[self animateToView:self.rCenterButton];
_step++;
}
else if ([sender tag]==kRightButtonCenter && _step==5){
[self pressedRightButtonCenter];
[self displayPromptText:#"TAP DOWN BUTTON"];
[self displayNavigationBarWithTitle:#"TAP DOWN BUTTON"];
[self animateToView:self.rDownButton];
_step++;
}
else if([sender tag]==kRightButtonDown && _step==6){
[self pressedRightButtonDown];
[self animateToView:self.rCenterButton];
[self displayPromptText:#"TAP CENTER BUTTON"];
[self displayNavigationBarWithTitle:#"TAP CENTER BUTTON"];
_step++;
}
else if ([sender tag]==kRightButtonCenter && _step==7){
[self pressedRightButtonCenter];
_step++;
}
else if ([sender tag]==kRightButtonCenter && _step==8)
{
[self pressedRightButtonCenter];
self.clusterHomeScreen.callTimer.hidden = NO;
[self.clusterHomeScreen runNextStep];
_step++;
}
else if ([sender tag]==kRightButtonCenter && _step==9)
{
self.clusterHomeScreen.callTimer.hidden = YES;
[self pressedRightButtonCenter];
_step++;
}
else if ([sender tag]==kRightButtonCenter && _step==10)
{
[self pressedRightButtonCenter];
[self finishTutorial];
}
else {
[self displayVisualFeedback:kVisualFeedBackIncorrectAnswer];
}
}
#pragma CUEClusterHomeSreenDataSource Methods
-(NSInteger)numberOfViewsForLeftScreen {
return [_leftActiveViews count];
}
-(NSInteger)numberOfViewsForRightScreen{
return [_rightActiveViews count];
}
-(NSInteger)numberOfViewsForCenterScreen {
return [_centerActiveViews count];
}
-(UIImageView *)inActiveViewForLeftScreenAtIndex:(NSInteger)index{
//if((index < [_leftInActiveView count]) && (index >=0)){
return [_leftInActiveView objectAtIndex:index];
//}
//return nil;
}
-(UIImageView *)activeViewForLeftScreenAtIndex:(NSInteger)index{
// if((index < [_leftActiveViews count]) && (index >=0)){
return [_leftActiveViews objectAtIndex:index];
//}
//return nil;
}
-(UIImageView *)inActiveViewForRightScreenAtIndex:(NSInteger)index{
//if((index < [_rightInActiveViews count]) && (index >=0)){
return [_rightInActiveViews objectAtIndex:index];
//}
//return nil;
}
-(UIImageView *)activeViewForRightScreenAtIndex:(NSInteger)index{
//if((index < [_rightActiveViews count]) && (index >=0)){
return [_rightActiveViews objectAtIndex:index];
//}
//return nil;
}
-(UIImageView *)inActiveViewForCenterScreenAtIndex:(NSInteger)index{
//if((index < [_leftInActiveView count]) && (index >=0)){
return [_centerInActiveViews objectAtIndex:index];
//}
//return nil;
}
-(UIImageView *)activeViewForCenterScreenAtIndex:(NSInteger)index{
// if((index < [_leftActiveViews count]) && (index >=0)){
return [_centerActiveViews objectAtIndex:index];
//}
//return nil;
}
This is the error i am getting now:
-[CUETutorialSixteenClusterRootController handleSwipeFrom:]: unrecognized selector sent to instance 0x79b71b0
2012-03-28 13:25:55.724 CUETrainer[1788:11f03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CUETutorialSixteenClusterRootController handleSwipeFrom:]: unrecognized selector sent to instance 0x79b71b0'
But its not actually doing anything.
Please help!!!!
The error says unrecognized selector sent to instance 0x79b71b0' most probably the names in .h and .m are different..
The target of the gesture recognizer needs to be the object that implements the selector. What's happening now when a swipe happens is that the gesture recognizer is doing [self.gestureReceiverButton handleSwipeFrom:recognizer]
You probably want this:
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
Change every instance of:
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
to
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipe:)];
Problem solved. Be very careful with your #selectors, what you place in this macro is NOT validated by the compiler. Code complete will help you with this.
Also you are adding four gesture recognizers to one view, while you can accomplish the same task with one. You can combine the valid directions using the bitwise OR operator, like so:
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp | UISwipeGestureRecognizerDirectionDown)];

Find and Remove Certain one UIGestureRecognizer among some same named UIGestureRecognizers

Hey, guys, I met a problem when trying to removeGestureRecognizer: from a view,
what i want to do is doubleTap one of the imageViews, and remove the tapped imageView's singleTap Gesture, without remove other imageViews singleTap Gesture.
here is how i generate views, gestures and the mechanisms:
.h
UITapGestureRecognizer *singleTap;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSInteger i;
for (i = 1; i <= 3; i++)
{
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(110, 70+80*(i-1), 100, 60);
imageView.backgroundColor = [UIColor whiteColor];
imageView.tag = i;
imageView.userInteractionEnabled = YES;
[self.view addSubview:imageView];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(doubleMethod:)];
doubleTap.numberOfTapsRequired = 2;
singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(singleMethod:)];
[singleTap requireGestureRecognizerToFail:doubleTap];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:singleTap];
}
}
- (void)singleMethod: (id)sender
{
NSLog(#"SingleTap");
}
- (void)doubleMethod: (id)sender
{
NSLog(#"%d",[((UITapGestureRecognizer *)sender).view.gestureRecognizers count]);
UIImageView *imageView = nil;
NSArray *tryToFindYou = [self.view subviews];
for (imageView in tryToFindYou)
{
if ([imageView isKindOfClass:[UIImageView class]] && imageView.tag == ((UITapGestureRecognizer *)sender).view.tag)
{
[imageView removeGestureRecognizer:singleTap];
}
}
NSLog(#"%d",[((UITapGestureRecognizer *)sender).view.gestureRecognizers count]);
}
but these lines I wrote can't find exactly the singleTap Gesture attached to the double-tapped imageView.
when NSLog the .gestureRecognizers count, it still 2, what it removed is the last imageView's singleTap Gesture, it became 1, which is correct.
I can't locate the first and second one, any ideas to locate them? thank you for reading :)
You should cycle through gestureRecognizers property of the UIView class, where the gestures are added, something like this:
for (imageView in tryToFindYou)
{
if ([imageView isKindOfClass:[UIImageView class]] && imageView.tag == ((UITapGestureRecognizer *)sender).view.tag)
{
for(UIGestureRecognizer *gesture in [imageView gestureRecognizers])
{
if([gesture isKindOfClass:[UITapGestureRecognizer class]])
{
if (gesture.numberOfTapsRequired == 1)
[imageView removeGestureRecognizer:gesture];
}
}
}
}