3

I have a UIView inside a UIScrollView, and the UIViewControllers for those views are not receiving the touch events. If I take the views out of the scroll view then it works.

UserInteraction is default ON of all views but it's still not working!

This must be possible and I'd be really grateful if someone could point me in the right direction!

Many Thanks,

DD_
  • 7,230
  • 11
  • 38
  • 59
Zeeshan
  • 586
  • 7
  • 15

2 Answers2

4

You can use the following method

 UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
 [panRecognizer setMinimumNumberOfTouches:1];
 [panRecognizer setMaximumNumberOfTouches:1];
 [panRecognizer setDelegate:self];
 [yourView addGestureRecognizer:panRecognizer];

And to handle it

 -(void)move:(id)sender {

    if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateChanged){
         // This will return you location in view
         CGPoint currentPoint =  [sender locationInView:self.view];

         // This will return you location in Scrollview
         CGPoint scrollPoint =  [sender locationInView:[[sender view] superview]];

    }
}
Shashank Kulshrestha
  • 1,556
  • 17
  • 31
2

add the following code to implementation file then touches moved

 @interface UIScrollView(Custom)
    @end
    @implementation UIScrollView(Custom)

   -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesMoved:touches withEvent:event];
}
    @end
Vinodh
  • 5,262
  • 4
  • 38
  • 68
  • 1
    @Vinodh. Can you also mention, why this has to be done, so that it would be helpful for newbies to understand what is going on. I believe, when the uiview is added to the scrollview, all the touch events are received by the scrollview and hence the touchesBegan, touchesMoved are not getting called. Please correct me if I am wrong. – Kiran Kulkarni Dec 04 '14 at 11:14