2
votes

I have a base view controller VC1 and another view controller VC2 that is modally presented over full screen (over VC1)

VC2 is semi transparent and I would like to forward all touch events from VC2 to VC1 when the user taps or scrolls. (VC1 has a few buttons and a scrollview)

Should I use some kind of custom container? How can I present VC2 to cover the screen and yet forward all touches to VC1? Is modal the right answer?

I have tried storing a reference to VC1 as a variable in VC2 and passing events to VC1 via touchesbegan but that has not worked.

Thank you.

1
what do you want? if scrollview in vc2 scrolling, scrollview in vc1 scroll? OR vc1 just catch scroll event of scrollview in vc2Nguyen Hoan
The buttons and scrollview are all in VC1. I want any touch/press on VC2 to go straight to VC1 and bypass VC2.freeBeerTomorrow

1 Answers

0
votes

If you want to pass event to different views, then you should use subView instead of VC2.

Make new UIView *secondView and add as subView of VC1.

[self.view addSubView:secondView];

Not put the following method in your VC1.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
   UIView *hitView = [super hitTest:point withEvent:event];

   // check your condition here, if button is pressed on secondView and you want to pass event on mainview the simply return mainView. This event will be passed to mainView.

   if ([secondView.button isEqual:hitView])
   {

      return self.view;
   }
   else
   {
      return nil;
   }

   return hitView;
 }