ios - addTarget:action:forControlEvents: ignored when interacting with separate UITapGestureRecognizer -
i'm new ios programming
i have code (abridged) looks following
uiview *somesubview = [[uiview alloc] initwithframe:...]; [self addsubview:somesubview]; [somesubview addtarget:self action:@selector(_handletaponview:) forcontrolevents:uicontroleventtouchupinside]; _tapgesturerecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(_handletap:)]; _tapgesturerecognizer.delegate = self; [self.view addgesturerecognizer:_tapgesturerecognizer];
unfortunately gesture recognizer triggers , views addtarget call not. i've tried commenting out gesture recognizer code , works, know not call addtarget on subview.
i solved using gesturerecognizer:shouldreceivetouch: , doing hit test sub view, feel i'm missing fundamental understanding here wouldn't require me adding manual hit test.
its important note don't want code in _handletap in _tapgesturerecognizer execute when have tapped on subview.
any guidance here? thanks!
try using:
_tapgesturerecognizer.cancelstouchesinview = no;
otherwise gesture recogniser intercept touches , not forward them further (in other words, gesture recogniser gets touch, handles it, , since cancel it, no other object gets touch). not cancelling, touch forwarded other object (recognisers or views) handle it.
Comments
Post a Comment