Ok This should be a simple task but it has been sending me insane.
All I am trying to achieve is a UIScrollView to be displayed behind static transparent toolbars on side and bottom of the screen. The structure is currently set up so that both the scrollView (subclass of UIScrollView) and the overlay (subclass of UIView) are subViews of the RootViewController.
scrollView = [[EMDrawScrollView alloc]initWithFrame:CGRectMake(0, 0, winSize.width, winSize.height)];
scrollView.userInteractionEnabled = YES;
[self.view addSubview:scrollView];
overlay = [[EMDrawOverlayView alloc]initWithFrame:CGRectMake(0, 0, winSize.width, winSize.height)];
overlay.userInteractionEnabled = NO;
[self.view addSubview:overlay];
THE ISSUE is that if I enable overlay.userInteractionEnabled the all touches go to the layer and can not get to the scrollView. But if I turn user interaction off the scrollView works correctly but I can not interact with the overlay.
With regards to handling touches I am collecting these with the RootViewController and sending them to the correct object like so:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *t1 = [[[event allTouches]allObjects]objectAtIndex:0];
CGPoint loc = [t1 locationInView:self.view];
if (CGRectContainsPoint(overlay.rightToolbar.frame, loc)) {
overlayTouched = YES;
[overlay touchesBegan:touches withEvent:event];
} else {
overlayTouched = NO;
[scrollView touchesBegan:touches withEvent:event];
}
}
I have a feeling that one fix will be to set the toolbars up as separate UIViews and add them as subviews to the View Controller so that the overlay is not taking up the entire screen but I would like to avoid this if there is another way.
OK…. Looks like there is not a simple answer to this question so I have gone abut solving this issue by doing as I said in the question and adding each overlaid as a UIView that has a Frame size of only a fraction of the size of its super view.
This worked well in the end because I was able to detect touchesBegan touches depending what view it was in and have touchesMoved and touchesEnd remain in that view which gave me a lot of control over user interaction.