ios - Limit Gesture Recognizer to Only One Specific UIView? -
i have uiview called myview
on myviewcontroller
. have uigesturerecognizer called swipeleft
(code below) detects when user swipes left on it.
the problem is: myviewcontroller
recognises same gesture on whole screen , performs action. app perform mymethod
when swipeleft
in particular area of myviewcontroller
, area being myview
.
uiswipegesturerecognizer *swipeleft = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(mymethod:)]; swipeleft.direction = uiswipegesturerecognizerdirectionleft; swipeleft.delaystouchesbegan = yes; [self.myview addgesturerecognizer:swipeleft];
more details: using residemenu , myviewcontroller
right menu, when visible, whole view of myviewcontroller
recognises swipes in directions. change recogniser in particular uiview myview
.
thanks!
first need add swipe gesture view controllers header file.
@property (strong, nonatomic) uiswipegesturerecognizer *swipeleft;
if in demorootviewcontroller.m, see call:
self.rightmenuviewcontroller = [self.storyboard instantiateviewcontrollerwithidentifier:@"rightmenuviewcontroller"];
this call awakefromnib, , it's first chance something. in here create swipe gesture. can not add view yet though, because outlets not set @ point. first time set in viewdidload, that's add gesture view. add view controllers implementation file
- (void)awakefromnib { self.swipeleft = [[uiswipegesturerecognizer alloc]initwithtarget:self action:@selector(mymethod:)]; } - (void)viewdidload { [super viewdidload]; [self.swipeview addgesturerecognizer:self.swipeleft]; } - (void)mymethod:(uiswipegesturerecognizer *)swipe { nslog(@"did swipe") ; }
finally need tell pan gesture in residemenu.m fail whenever our swipeleft gesture occurs. way add following code residemenu.m @ line 220. that's @ end of viewdidload method.
if ([self.rightmenuviewcontroller iskindofclass:[demovc class]]) { demovc *rightvc = (demovc *)self.rightmenuviewcontroller; if (rightvc.swipeleft) { [pangesturerecognizer requiregesturerecognizertofail:rightvc.swipegesture]; } } }
this assuming custom vc called demovc. need import custom vc residemenu.m this:
#import "demovc.h"
please let me know if worked out you, , if there's else can with.
Comments
Post a Comment