I have a subview, containing a view controller with navigation buttons, that I want to pass touches through if the buttons aren't hit.
I've found some suggestions to override HitTest on the container view, but it either doesn't work or I'm not doing it correctly.
So I have a parent view controller, created with a storyboard, and I added my subview like so in ViewDidLoad:
containerOne = new TestView(new RectangleF(0, 0, (float)screenWidth, (float)screenHeight));
containerOne.TranslatesAutoresizingMaskIntoConstraints = false;
containerOne.AutosizesSubviews = true;
containerOne.BackgroundColor = UIColor.FromRGBA(0,0,0,0);
View.AddSubview(containerOne);
var firstChild = new TestController();
AddChildViewController(firstChild);
containerOne.AddSubview(firstChild.View);
containerOne.Frame = new RectangleF((float)containerOne.Frame.X, (float)containerOne.Frame.Y, (float)containerOne.Frame.Width, (float)firstChild.View.Frame.Height + 200);
firstChild.View.Frame = containerOne.Bounds;
firstChild.DidMoveToParentViewController(this);
And my Test View where I've attempted to implement a fix:
public class TestView : UIView
{
public TestView(CGRect frame) : base(frame)
{
}
public override UIKit.UIView HitTest(CoreGraphics.CGPoint point, UIKit.UIEvent uievent)
{
UIView hitView = base.HitTest(point, uievent);
if (hitView == this)
{
Console.WriteLine("null");
return null;
}
Console.WriteLine("hitTestView");
return hitView;
}
}
The subview's view controller (TestController referenced above) has a button at the bottom of the screen and the rest is empty. I'd like to be able to hit the parent view controllers buttons, but nothing happens and I can't get through my subview's layer. My Console.WriteLine("null") never appears.
I'd really appreciate some help on this so I can figure this out! Thanks!