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)

  1. 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]; } 
  2. add ibaction tap gesture recognizer example - (ibaction)tappedoutside:(id)sender;

  3. 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

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -