0

I've made a UIScrollView the first responder. I need to maintain touch events to a -touchesEnded:withEvent: method on a view behind it. I've tried using the -nextResponder method and that failed. I've tried forwarding -touchesEnded:withEvent: to the view behind it and that fails.

How do I get this to work? The UIScrollView wont work unless it is the first responder or gets events some other way.

Thank you for any help. Shame Apple's documentation and APIs are terrible in areas.

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
Matthew Mitchell
  • 5,293
  • 14
  • 70
  • 122

1 Answers1

0

UIScrollView handles touches in a slightly unusual way. From the class reference:

Because a scroll view has no scroll bars, it must know whether a touch signals an intent to scroll versus an intent to track a subview in the content. To make this determination, 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...

A subview within the scroll view's content view will eventually receive non-scrolling touches to the scroll view.

A superview of a scroll view is unlikely to see touch events as its -hitTest:withEvent: will return the scroll view so touch events will be sent to the scroll view which is not required to forward them back up the responder chain to the parent view.

First responder does not influence the delivery of touch events, see http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/EventsiPhoneOS/EventsiPhoneOS.html#//apple_ref/doc/uid/TP40009541-CH2-SW5

The first responder is the responder object in an application (usually a UIView object) that is designated to be the first recipient of events other than touch events...

Jonah
  • 17,918
  • 1
  • 43
  • 70
  • Okay, thank you but I have no idea to get around it. I must get around it. The area I need to get touch positions for is where the scroll view is. – Matthew Mitchell Jan 05 '11 at 02:21
  • OK but your view should receive touches. Is the problem more specifically that you want your view to receive touches which also cause the scroll view to scroll? – Jonah Jan 05 '11 at 02:35
  • It doesn't receive touches for any touch. :( Perhaps the simulator des not implement this correctly. I shall try my iphone with it. Thank you for your help. – Matthew Mitchell Jan 05 '11 at 17:25
  • I've never had a problem with scroll views in the simulator so I think we need more detail from you, how are you trying to detect touches on that view and what makes you think they are never received? I'm not sure what else I can offer without seeing your actual implementation. – Jonah Jan 05 '11 at 17:54
  • Well, any other code wont be related and there is tonnes of it. All I so is add the UIScrollView to a EAGLView and then a UIImageView on the EAGLView which overlaps the UIScrollView. I use touchesEnded:withevent on the EAGLView to determine if the screen was touched in an area which happens to be what the UIImageView is for. The UISCrollView must overlap or there is a graphical issue where the UIScrollView contents wont show under the partially transparent UIImageView. – Matthew Mitchell Jan 05 '11 at 22:03
  • I've had enough of this. I'm just going to have to have a nasty graphical glitch in my app because of Apple's unfathomable APIs. – Matthew Mitchell Jan 05 '11 at 23:50
  • What you just described is different from the original question. If your image view is a sibling of the scroll view rather than a child of the scroll views content view then you should not expect touches sent to the scroll view to reach the image views. Touches are optionally sent up the responder chain to parent views. Not to a views siblings. – Jonah Jan 06 '11 at 00:16