I thought when a view is touched or tapped on, its handler get called first, and then its superview's handler is called (propagate upward).
But is it true that if the superview's userInteractionEnabled
is set to NO, then all subviews and offspring is also disabled for user interaction? What if we want to disable for just the main view but don't want to disable for the subviews?
First Method
Second Method
You can override
hitTest(_:withEvent:)
to ignore the view itself, but still deliver touches to its subviews.You cant do that,
Instead you would change the arrangment of your views like following:
To
So your current main view and you current subviews will become siblings, children of a new container view
If this may be helpful, I found this in Programming iOS 5 by Matt Neuburg, p. 467:
Further more, Apple's Event Handling Guide for iOS says:
and Programming iOS 5 by Matt Neuburg, p.485 mentioned that if a view is marked
userInteractionEnabled
asNO
, orhidden
asYES
, or opacity is close to 0, then the view and its subview will not be traversed byHitTest
(and therefore not considered for any touch).