I have TransparentUIView on top of RedOrGreenUIView. TransparentUIView has a UILongPressGestureRecognizer attached to it. Once user begins a long touch on it, I check for .Changed status of this LongPressGesture, and execute below hitTest:
var p:CGPoint = rec.locationInView(self.view)
var selectedView = view.hitTest(p, withEvent: nil)
if selectedView != nil {
if selectedView == TransparentUIView {
println("TransparentUIView is being touched")
}
}
I get TransparentView as selectedView fine. However I need to be able to conduct a hitTest on RedOrGreenUIView at the same time, which is underneath TransparentUIView. I cant get my head around to accomplishing this. Please help.
Create a custom view for your container and override the pointInside: message to return NO when the point isn't within an eligible child view, like this:
swift version
Swift 4 version :
I am currently working on a transparent Help Overlay for iOS apps and was looking for a good answer on this myself.
I couldn't really find anything, so decided to look a bit further. The apple documentation on hitTest says it doesn't include views that have a transparency of < 0.1, are hidden or have userInteractionEnabled to false.
That last one gave me an idea and it's something that seems to work pretty good.
Try the following (I still need to test it further, but it seems to be allright):
If one UIView gets touches, others underneath don't get any.
So either you can have a central class that passes touches to both your UIView objects, or the first UIView, the one that is on top, passes its UITouch object to the UIView underneath and conducts the hitTest.