Search code examples
iphoneipaduiviewuiscrollviewtouchesbegan

UIView added to a ScrollView and touchesDidBegin issue


Im adding a UIView as a subView to a scrollView. However, I wish to detect touches in the UIView. But i notice that when i do something like this:

[self.myScrollView addSubview:myView];

then, the touchesDidBegin method is never called when i touch the subview. However, if i do the following,

[self.view addSubview:myView];

then, the touchesDidBegin method is called. However, now the subView does not scroll along with the scroller obviously.

I want "myView" to be added to the scrollView as a subview so that it scrolls along with it and also detects touches on it. Any way to accomplish this?


Solution

  • The same has already discussed here, plz find the link to similar SO post.

    Handling touch events within a child UIScrollView

    Touch events not working on UIViews inside UIScrollView uiscrollview