Reputation: 37
I have implemented my own custom subclass of UIView
and overridden the drawRect:
method.
In my custom view I also want the handle touches, so I also overridden touchesBegan
, touchesMoved
and touchesEnded
.
This works fine but if the number of views on the screen increases then I have to use a UIScrollView
as the root view of my UIViewController
.
Once my custom UIView
becomes the subview of UIScrollView
, then it does not receive the touch events. Even though I move my finger within my custom UIView
, the scroll view gets scrolled (all my touch events go to the UIScrollView
).
How do I solve this problem?
Upvotes: 2
Views: 5184
Reputation: 11682
There are several approaches you could try:
Try setting the below properties on the UIScrollView
:
scrollView.delaysContentTouches = NO;
scrollView.canCancelContentTouches = NO;
I would personally recommend using a UIGestureRecognizer
, but it depends on your specific situation (any of these options may work fine for you).
Upvotes: 7
Reputation: 6383
Have a look at this response from another question: https://stackoverflow.com/a/4629821/193254
You'll have to subclass the scrollview too, and implement that hitTest:
method.
Upvotes: 0