Reputation: 327
I am subclassing a view which is the same size as my main ViewController (1024x768). This subview has a transparent background and contains buttons that are sized 50w X 50h and are positioned dynamically.
My issue is that I need to interact with content and buttons that exist beneath this view but this subview is blocking that interaction.
I've seen some posts address a similar problem, but I am unclear of the actual usage.
Upvotes: 0
Views: 706
Reputation: 17906
-pointInside:withEvent:
is how iOS asks if a touch is within a particular view. If a view returns YES, iOS calls -hitTest:withEvent:
to determine the particular subview of that view that was touched. That method will return self
if there are no subviews at the location of that touch. So you can pass any touches that aren't on subviews back to views behind this one by implementing -pointInside:withEvent:
like this:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
return ([self hitTest:point withEvent:event] != self);
}
If you need to catch some touches that aren't on subviews, your implementation will be more complicated, but this method is still the right place to tell iOS where your view is and accepts touch events.
Upvotes: 2
Reputation: 753
If all else fails you can bring those subviews to the front programmatically using
[self.view bringSubviewToFront:buttonToClick];
Upvotes: 1