iPhone SDK - UIButton on a UIScrollView touch interactions
I have a UIScrollView
which is doing some custom pinch zooming. To do this I subclassed UIScrollView
, the overwrote the touch methods t开发者_如何学JAVAouchesBegan
, touchesMoved
, and touchesEnded
. Everything works well and as expected.
My problem comes when I try to add a series of UIView subviews, I can only detect taps on my UIScrollView
when the UIView
UserInteractions
is set to NO
. I would like to be able to continue to detect two finger taps on my UIScrollView
, AND a single finger tap on any of my UIView subview.
Is this possible?
I've tried countless number of ways with little help. Does anyone have any experience in this?
Cheers, Brett
Apple's documentation for UIScrollView explains how it does it:
it temporarily intercepts a touch-down event by starting a timer and, before the timer fires, seeing if the touching finger makes any movement. If the timer fires without a significant change in position, the scroll view sends tracking events to the touched subview of the content view. If the user then drags their finger far enough before the timer elapses, the scroll view cancels any tracking in the subview and performs the scrolling itself.
There are a couple of methods for interception given as answers to this question: How to make a superview intercept button touch events?
Any UIView with userInteractionEnabled will block touches from reaching views under it. You may have to rethink how you are structuring your layout. Or subclass the UIView to change how it's handling touches.
精彩评论