我在mainScene中得到这样的手势
// listen for swipes to the left
UISwipeGestureRecognizer * swipeLeft= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeLeft];
// listen for swipes to the right
UISwipeGestureRecognizer * swipeRight= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeRight];
我在这个mainScene
上添加了newLayer(CCNode)[mainScene addChild:newLayer];
当我在newLayer上滑动时,会调用mainScene手势处理程序。
我想在添加newLayer时关闭mainScene的滑动手势处理程序。
我该怎么做?
答案 0 :(得分:1)
您可能希望查看gestureRecognizer:shouldReceiveTouch:
或UIGestureRecognizerDelegate
协议指定的任何其他方法,如UIGestureRecognizerDelegate Protocol Reference所示
例如,您可以尝试...
static NSMutableArray *_swipes;
static BOOL _shouldCancel;
- (void)viewDidLoad {
_swipes = @[].mutableCopy;
_shouldCancel = YES;
for(UIGestureRecognizer *gesture in [mainScene gestureRecognizers]) {
if([gesture isKindOfClass:[UISwipeGestureRecognizer class]]) {
gesture.delegate = (id)self;
[_swipes addObject:gesture];
}
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return ![_swipes containsObject:gestureRecognizer] && _shouldCancel;
}
这样,您可以将_shouldCancel
修改为NO
或YES
,具体取决于您希望禁用滑动的时间。