Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a UIView under a UIScrollView to detect touches?

I have a UIScrollView ontop of my UIViewController recreating an effect like in the Gowalla iPhone app when you're on a spot's page. Under my scroll view I have a button that I want to be able to perform it's action even when the scroll view's frame covers it up (where it's ontop of the button, the scroll view's clear). How would I do something like this? Is it possible? (it has to be, Gowalla [somehow] did it)

like image 855
jonahgrant Avatar asked Mar 20 '11 01:03

jonahgrant


1 Answers

As for me, I will transfer touch event to another view by override following methods.

  • – touchesBegan:withEvent:
  • – touchesMoved:withEvent:
  • – touchesEnded:withEvent:
  • – touchesCancelled:withEvent:

Like this way,

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     // pass touch event by default implement.
     [super touchesBegan:touches withEvent:event]; 

     // redirect the touch events. 
     [anotherView touchesBegain:touches withEvent:event];    
}

hitTest:withEvent: is used to decide which view should response touch event on the view hierarchy tree. If the view doesn't want to response touch event, it will return nil in hitTest. As result the above touch event methods won't be called.

like image 200
AechoLiu Avatar answered Oct 15 '22 22:10

AechoLiu