ios - Close subview when the parent view is touched -
i have parentview
, subview childview
. childview
positioned in middle of parentview
, half it's size.
i want close childview
when user tap on parentview
.
my code follows creates uitapgesturerecognizer
in parentview
once childview
open.
my problem tap event triggered when user touches view, not parentview
.
thus, wondering how can make event happen if parentview touched or other possible close sub view if parent touched.
- (ibaction)selectroutine:(id)sender { uistoryboard *storyboard = [uistoryboard storyboardwithname:@"storyboard" bundle:nil]; createroutinepopupviewcontroller* popupcontroller = [storyboard instantiateviewcontrollerwithidentifier:@"createroutinepopupview"]; popupcontroller.view.center = cgpointmake(self.view.bounds.size.width / 2, self.view.bounds.size.height / 2); _ass = popupcontroller; //tell operating system createroutine view controller //is becoming child: [self addchildviewcontroller:popupcontroller]; //add target frame self's view: [self.view addsubview:popupcontroller.view]; //tell operating system view controller has moved: [popupcontroller didmovetoparentviewcontroller:self]; uitapgesturerecognizer *singletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handlesingletap:)]; [singletap setnumberoftapsrequired:1]; [self.view addgesturerecognizer:singletap]; } -(void) handlesingletap: (id) sender { nslog(@"test string"); }
you need use uigesturerecognizerdelegate , implement following method.
it check touched view.
- (bool)gesturerecognizer:(uigesturerecognizer *)gesturerecognizer shouldreceivetouch:(uitouch *)touch { if( [touch view] != popupcontroller.view) return yes; return no; }
Comments
Post a Comment