第三方搜狗键盘keyboardwillshow通知走三次解决方案

NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification , object: nil)

func keyboardWillShow(notification:NSNotification){
        let keyboardInfo = notification.userInfo![UIKeyboardFrameEndUserInfoKey]
        
        let keyboardHeight:CGFloat = (keyboardInfo?.CGRectValue.size.height)!
        
        if keyboardHeight != 0{
            UIView.animateWithDuration(1.0) {
                if UIScreen.mainScreen().bounds.height-self.loginButton.frame.origin.y-keyboardHeight < 0 {
                    self.view.frame = CGRectMake(0, (UIScreen.mainScreen().bounds.height-self.loginButton.frame.origin.y-keyboardHeight), self.view.frame.size.width, self.view.frame.size.height)
                }else {
                    self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
                }
            }

        }
        
    }

  

posted @ 2016-04-11 10:10  torrescx  阅读(1515)  评论(0编辑  收藏  举报