2

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.

Community
  • 1
  • 1
TheBen
  • 3,410
  • 3
  • 26
  • 51
  • Is [this answer](http://stackoverflow.com/questions/40701494/how-to-detect-the-location-of-my-finger-through-in-a-scrollview-or-webview-in-sw/40701751#40701751) useful to your case? – Ahmad F Nov 27 '16 at 10:10
  • nope! Question is how to find if I have multiple layers (subviews) at the location I am touching not to find x and y. – TheBen Nov 27 '16 at 10:25
  • Are you using touchesBegun method to detect touch or UIGestures? – Syed Qamar Abbas Nov 27 '16 at 11:42

1 Answers1

0

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
}
}
Syed Qamar Abbas
  • 3,637
  • 1
  • 28
  • 52
  • I have multiple UIViews and really all I need is to check if there's a UIView where I'm touching as I move that touch point. I think I figured it out last night , the hitTest is an easy way and then I just check of the tags as I know my UIView tags are greater than a number. So as long as the returned view's tag meets the condition I know there's a uiview there. Any way, I think your answer is pretty close so , thumb's up ! – TheBen Nov 27 '16 at 17:55