Home > DeveloperSection > Forums > GestureRecognizer not working with UIScrollView in Objective-C?
Jessica James
Jessica James

Total Post:16

Points:114
Posted on    February-20-2016 7:24 AM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 315  View(s)
Rate this:
I have created an app using UIScrollView and I also added a gesture recognizer but calling method in gesture recognizer is not working.
this is the code:
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(doubbleTapHandler:)];
[self.scrollView addGestureRecognizer:doubleTap];
and this is the implementation:

-(void)doubleTapHandler:(UITapGestureRecognizer*)recognizer
{
//here I am doing some UIRelatedTasks
}
Can any one tell me how can I solve this issue?


Tarun Kumar

Total Post:210

Points:1614
Supported
Posted on    February-22-2016 5:40 AM

According to the code you are provided above, you are created tap gesture recognizer and add it to the scrollview. All the thing is correct but tell me one thing how your scrollview will find that double tap is happening on it.
So add this line of code, this scrollview will count the number of taps if 2 tap will happened on it then it will coll the selector method doubleTapHandler:
doubleTap .numberOfTapsRequired=2;
Here is your complete code:
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget: self
action:@selector(doubbleTapHandler:)];
doubleTap.numberOfTapsRequired = 2;
[self.scrollView addGestureRecognizer: doubleTap];

Modified On Feb-22-2016 05:41:37 AM

Don't want to miss updates? Please click the below button!

Follow MindStick