0

no matter how much I tried I couldn't have access (Handle scrolling/Touchevents) to the overlapping area (right triangle) between two square shaped views A and B (A in on top of B)as shown in this image

enter image description here

I want the right part (triangle B) with is defined by UIbezierpath to handle the scrolling for the view beneath it(which is B). I couldn't have access to it by pointInside: withEvent: since its a bezierpath. Even touchesBegan:withEvent: didn't work at all

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self.view];
    if ([leftPath containsPoint:touchPoint])
    {  //Do something
     }
 }

Please help.

Mi-Creativity
  • 9,554
  • 10
  • 38
  • 47

1 Answers1

1

You have to implement hitTest method of UIView to detect touch on particular view. Simply subclass your View and implement hitTest method.

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{

if ([path containsPoint:point]){

    return [super hitTest:point withEvent:event];
}
else{

    return nil;
}

}
technerd
  • 14,144
  • 10
  • 61
  • 92
  • Thank you for the answer! `hitTest: withEvent` now gets called when i touch the view itself but how can i make the rest of the view (overlapping section with the view beneath it) become transparent so the view beneath it gets my touch (scrolling etc)?? –  Dec 19 '15 at 19:25
  • Are you trying to make shape for PhotoCollage Application ? – technerd Dec 21 '15 at 05:25
  • I did it by defining two separate views, subclassing uiview and each having a triangular mask, implementing `hitTest:withEvent:` and `point:withEvent` only on the top view and then adding a subview of another uiview in them which they subclass the uiview and override methods for pinch,pan etc. thank you, now touch events work on both views. I also tried to use `topView.layer.zPosition = 0.1; `and `downView.layer.zPosition = 0;` to make sure ;) –  Dec 21 '15 at 15:35