Meta Interview Question

How would you implement UIView hitTest mehtod?

Interview Answers

Anonymous

Dec 9, 2018

UIView * hitTest(UIView *view, CGPoint point, UIEvent *event) { if (view == nil) return nil; if (CGRectContainsPoint(view.bounds, point)) return view; else hitTest(view.superView, point, event); }

1

Anonymous

Feb 17, 2018

Thanks for sharing your experience and much appreciated. It would be really great if could post remaining questions as well to help others to fulfil their dream job.

Anonymous

Dec 9, 2018

UIView * hitTest(UIView *view, CGPoint point, UIEvent *event) { if (CGRectContainsPoint(view.bounds, point); return view; for (UIView *view in view.subViews) { hitTest(view, point, event); } }

1