Reputation: 1
I have two UIViews. On second "UIView" I have one UIButton, but it must be over the both views. When I click lower middle UIButton - event is fire, but when I click above the middle - nothing works.
How to fix it?
Upvotes: 0
Views: 48
Reputation: 10327
You should create a subclass of UIView
for UIView2
and override hitTest
like this:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (!self.clipsToBounds && !self.hidden && self.alpha > 0) {
for (UIView *subview in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subview convertPoint:point fromView:self];
UIView *result = [subview hitTest:subPoint withEvent:event];
if (result != nil) {
return result;
}
}
}
return nil;
}
Upvotes: 0