TheeBen TheeBen - 12 days ago 9
Objective-C Question

How can I find out if I have a UIView where I am long pressing as I move the touch point?

I am trying to figure out how I can determine if my touchpoint is where I have a UIView as subview or not. The background is UIView itself that I am adding multiple other UIViews to ... So as I long press and am changing the position while holding the touch, I'd like to know if there's a UIView at that point or not.

I have been thinking, still not clear how to go about it but came across this which makes me think of getting the indexes of hierarchy and check of it is larger than 1. But how could I do that for where I'm touching?

Any hint or clue would be appreciated.

Answer

You have to store both reference in two objects myParentView and mySubView now just use this method..

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    CGPoint locationPoint = [[touches anyObject] locationInView: myParentView];
    UIView* viewYouWishToObtain = [self hitTest:locationPoint withEvent:event];
    if(mySubView == viewYouWishToObtain){

         //That view is touched
    }else{
        //That view is not touched
}
}