Reputation:
This is an odd scenario, but I have two overlapping UIViews, and I need to display one above the other, but give the lower one precedence on receiving input. If that makes any sense. I can clarify if needed.
Preferably I would like to do this in Interface Builder, but assuming that is not possible, is there a way to do it programmatically?
Edit: Got it working, thanks to @jaydee3. Just override the hitTest:
method of UIView1 as follows. UIView2 is self.otherView
.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (self.otherView && [self.otherView pointInside:[self.otherView convertPoint:point fromView:self] withEvent:event])
{
return [self.otherView hitTest:[self.otherView convertPoint:point fromView:self] withEvent:event];
}
return [super hitTest:point withEvent:event];
}
Upvotes: 3
Views: 61
Reputation: 9977
In case you don't need input on view1, just set view1.userInteractionEnabled = NO
. This can be done in IB.
Otherwise, you have to use some code. Eg. subclass UIView for the view1 and override the hitTest: …
method. If the touched point is overlapping with the other view, return [view2 hitTest: …]
.
Upvotes: 2