TheeBen TheeBen - 1 year ago 63
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 Source

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
        //That view is not touched
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download