ios - touchesBegan cancel UISwipeGestureRecognizer -
i have general touchesbegan in viewcontroller
- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { nslog(@"--[%s:%d]",__pretty_function__,__line__); }
this seems cancel uiswipegesturerecognizer. (not fired)
uiswipegesturerecognizer *swipeleft = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipe:)]; uiswipegesturerecognizer *swiperight = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipe:)]; [swipeleft setdirection:uiswipegesturerecognizerdirectionleft]; [swiperight setdirection:uiswipegesturerecognizerdirectionright]; swiperight.numberoftouchesrequired=1; swipeleft.cancelstouchesinview=no; swiperight.cancelstouchesinview=no; swipeleft.delaystouchesbegan = yes; swiperight.delaystouchesbegan = yes; self.viewswipe.userinteractionenabled=yes; [self.viewswipe addgesturerecognizer:swipeleft]; [self.viewswipe addgesturerecognizer:swiperight];
any idea? :)
touchesbegan::
gets called before gesture recognizers, , indeed override them.
if wish support both tap , swipe on same view, can use uitapgesturerecognizer, , call requiregesturerecognizertofail.
so, add following bottom of code sample:
uitapgesturerecognizer *taprecognizer = [[uitapgesturerecognizer alloc] init]; taprecognizer.numberoftapsrequired = 1; [taprecognizer requiregesturerecognizertofail swipeleft]; [taprecognizer requiregesturerecognizertofail swiperight];