swift - in ios 9 with hardware keyaboard attached, keyboard will hide triggers when clicking on a text field -
noticed in ios 9 keyboardwillhide event incorrectly triggered when clicking on textbox hardware keyboard attached. did change in ios9? should somehow try detect keyboard not shown, or should try figure out why keyboardwillhide notification being called , prevent it?
import uikit class basetextfieldviewcontroller: uiviewcontroller { // mark: keyboard handling override func viewwillappear(animated: bool) { super.viewwillappear(animated) nsnotificationcenter.defaultcenter().addobserver(self, selector: "keyboardwillshow:", name: uikeyboardwillshownotification, object: nil) nsnotificationcenter.defaultcenter().addobserver(self, selector: "keyboardwillhide:", name: uikeyboardwillhidenotification, object: nil) } override func viewwilldisappear(animated: bool) { super.viewwilldisappear(animated) nsnotificationcenter.defaultcenter().removeobserver(self) } func keyboardwillshow(sender: nsnotification) { if let userinfo = sender.userinfo { if let keyboardheight = userinfo[uikeyboardframeenduserinfokey]?.cgrectvalue.size.height { uiview.animatewithduration(0.25, animations: { () -> void in self.view.center = cgpointmake(self.view.center.x, self.view.center.y - keyboardheight) }) } } } func keyboardwillhide(sender: nsnotification) { if let userinfo = sender.userinfo { if let keyboardheight = userinfo[uikeyboardframeenduserinfokey]?.cgrectvalue.size.height { uiview.animatewithduration(0.25, animations: { () -> void in self.view.center = cgpointmake(self.view.center.x, self.view.center.y + keyboardheight) }) } } } }
Comments
Post a Comment