Question

I have a ScrollView that contains a ContainerView. The ContainerView contains another View that the user is supposed to be able to pan around in.

The scrollView scrolls vertical only, the "view inside the containerView" is panable in all directions. Here is what I have

self.scrollView.contentSize = CGSizeMake(1024,1440);
self.modelController = [self.storyboard instantiateViewControllerWithIdentifier:@"LCProduct3DViewController"];
self.modelController.meshIdentifier = self.meshIdentifier;
[self addChildViewController:self.modelController];
self.modelController.view.frame = self.threeDView.bounds;
[self.threeDView addSubview:self.modelController.view];

What happens is that the touch events inside the modelController's view and the ones outside the modelControler's view but inside the scrollview bounds seems to be getting the the way of each other. I played around with

self.scrollView.canCancelContentTouches = NO;
self.scrollView.delaysContentTouches = NO;

but havent found a working solution yet.

Any Ideas ?

Thanks in advance

Was it helpful?

Solution

as can be found in other places: The trick is to subclass the scrollView and override the hitTest method like this:

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

    if ([result isKindOfClass:[GLKView class]]) {
        self.scrollEnabled = NO;
    } else {
        self.scrollEnabled = YES;
    }
    return result;
}

this way - if the hittest for the innver view is positive, scrolling for the scrollview is disabled and only the innver view will get the event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top