Question

I have made a CCNode which I dubbed ScrollNode, basically it is a CCNode which crops a certain region of a child node, and this child node is moving on it's x and y position based on the scroll location of a transparent overlaying UIScrollView.

I wanted a ScrollView in Cocos2d which felt native to the iOS platform and it does a good job.

However a problem arises with this way of handeling things. The touches for CCButton on a node which can be scrolled are not called (because there is a transparent UIScrollView over that region) is it possible to pass through the touches from the UIScrollView when it is a "tap" gesture and not a "pan gesture"

I have tried the following:

// Make sure touches are passed trough all views
for(UIGestureRecognizer *recognizer in self.scrollView.gestureRecognizers)
{
    recognizer.cancelsTouchesInView = NO;
}

But this doesn't seem to make any difference.

Kind Regards,

Was it helpful?

Solution 2

Seems like I've fixed it. I have subclassed the UIScrollView, and passed the touches* events to it's parent. Which seems to have no effect on the scrolling, but makes sure it does trigger the tap event for CCButtons.

#import "ScrollNodeScrollView.h"

@implementation ScrollNodeScrollView

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.superview touchesCancelled:touches withEvent:event];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.superview touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.superview touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)aTouches withEvent:(UIEvent *)anEvent
{
    [self.superview touchesEnded:aTouches withEvent:anEvent];
}

@end

OTHER TIPS

The way I prefer to solve this is to set up my own UITapGestureRecognizer on the UIScrollView instance. The handler then just passes the touch location to the code that handles taps in my scene.

The tap and pan gesture recognizers know how to interact with each other so it still provides the native experience.

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