ios - Get keyboard height while being dismissed interactively with scroll -


i'm creating chat interface , whatsapp, have created "scrolltobottom" button, appears when user scrolls collection distance. button follows keyboard frame when keyboard appears , when disappears, problem when keyboard being dismissed interactively, can't make button follow keyboard frame. after keyboard hidden system sends notification , button changes constant.

i have tried keyboard notifications , none of them helped me issue. need in time, makes button follow keyboard without delay. uikeyboardwillchangeframenotification haven't worked me.

nsnotificationcenter.defaultcenter().addobserver(self,                                                          selector:#selector(self.keyboardwillshow(_:)),                                                          name:uikeyboardwillshownotification,                                                          object:nil) nsnotificationcenter.defaultcenter().addobserver(self,                                                          selector:#selector(self.keyboardwillhide(_:)),                                                          name:uikeyboardwillhidenotification,                                                          object:nil)  private func configureconstantviewnewmessages(notification: nsnotification){         if let userinfo = notification.userinfo {             let animationduration = (userinfo[uikeyboardanimationdurationuserinfokey] as! nsnumber).doublevalue             let keyboardendframe = (userinfo[uikeyboardframeenduserinfokey] as! nsvalue).cgrectvalue()             let convertedkeyboardendframe = view.convertrect(keyboardendframe, fromview: view.window)             let rawanimationcurve = (notification.userinfo![uikeyboardanimationcurveuserinfokey] as! nsnumber).unsignedintvalue << 16             let animationcurve = uiviewanimationoptions(rawvalue: uint(rawanimationcurve))              self.knewmessages.constant = cgrectgetmaxy(view.bounds) - cgrectgetminy(convertedkeyboardendframe) + 10              uiview.animatewithduration(animationduration, delay: 0.0, options: [.beginfromcurrentstate, animationcurve], animations: {                 self.view.layoutifneeded()                 }, completion: nil)         }     } 

with code above, call method configureconstantviewnewmessages animate constant of button (knewmessages) , can change position according keyboard height.

thanks support , sorry english mistakes.

please use below code might work you.

 override func viewwillappear(animated: bool) {            nsnotificationcenter.defaultcenter().addobserver(self, selector: "keyboardwillshow:", name: uikeyboardwillshownotification, object: nil)  }    func keyboardwillshow(notification:nsnotification) {         let userinfo:nsdictionary = notification.userinfo!         let keyboardframe:nsvalue = userinfo.valueforkey(uikeyboardframeenduserinfokey) as! nsvalue         let keyboardrectangle = keyboardframe.cgrectvalue()         let keyboardheight = keyboardrectangle.height         print(keyboardheight)     } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -