ios - Swift keyboard won't dismiss by touchesBegan -
i using
override func touchesbegan(touches: set<nsobject>, withevent event: uievent) { self.view.endediting(true) }
in order dismiss keyboard when user taps somewhere, won't work. , don't errors
my vc built up: view > visual effect view > view > scroll view > uibutton (it covers screen , works exit/back button prev vc) > designable view (here login form is)
in interface builder, drag
tap gesture recognizer
on view want dismiss keyboard after tap gesture or can add gesture code :-(void)viewdidload { [super viewdidload]; uitapgesturerecognizer *gesturerecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tappedoutside:)]; gesturerecognizer.cancelstouchesinview = no; [scrollview addgesturerecognizer:gesturerecognizer]; }
add
ibaction
tap gesture recognizer
example- (ibaction)tappedoutside:(id)sender;
in implementation file add :
-(ibaction)tappedoutside:(id)sender { [self.view endediting:yes]; }
swift:
var tap : uitapgesturerecognizer = uitapgesturerecognizer(target: self,action: "dismisskeyboard") self.view.addgesturerecognizer(tap) func dismisskeyboard() { self.view.endediting(true) }
Comments
Post a Comment