Posts

Showing posts from September, 2020

hitTest on iOS to identify the view being hit

Image
HitTest on iOS Use hitTest, to identify the view being tapped. The below method allows us to identify the view being selected. We can use it, to identify the view from which we would like to hide the touch events or identify the view we are interested into. Example: In the below case when we tap on Black View we can show an alert like "Black View tapped!" , if we tap on Red View , we can show an alert  "You are not allowed to tap on Red View" .  override func hitTest ( _ point: CGPoint , with event: UIEvent ?) -> UIView ? { } Here is a simple implementation of the method, to identify the view being hit. View hierarchy being used is listed below:- Blue(parent) - Red(child) - Green(child) - Yellow (child) - Orange (child) - Black (child) - White (child) So lets' start with override of hitTest method.      override func hitTest ( _ point: CGPoint , with event: UIEvent ?) -> UIView ? {         //1         if let viewAvailable = findPoin