iOS Tips: Perform Hit Test on a View

The gate to deep space by Dank97
func hitTest(_ point: CGPoint,with event: UIEvent? ) -> UIView?

If we have multiple subviews in a view, how to perform a hit test on views?

isUserInteractionEnabled = false
override func hitTest(_ point: CGPoint,with event: UIEvent? ) -> UIView?{    let view = super.hitTest(point,with: event)    if view = self{    return nil //if green view, do nothing    }   return view //if purple view, return it to do something
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store