iOS11中的键盘问题

时间:2017-09-28 02:02:05

标签: swift xcode ios11

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillShow, object: nil)

func keyboardWillHide(notification: NSNotification) {
    if let rect = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {

    }
}

顺便说一下,函数没有给出正确的RectValue。 这有什么不对吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

 NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)

 NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)

 func keyboardWillHide(notification: NSNotification) {
        if let rect = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {

        }
    }
 func keyboardWillShow(notification: NSNotification) {
        if let rect = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {

        }
    }