如何解决与UIResponder不能识别此问题?

时间:2019-04-21 21:59:19

标签: swift uiresponder

我正在Swift中制作一个NotePad应用程序,并且遇到了以下问题:

  

类型“ Notification.Name”(也称为“ NSNotification.Name”)没有成员“ UIResponder”

这些是我键入的代码行:

@objc func updateTextView (notification : Notification) {
    let userInfo = notification.userInfo!

    let keyboardEndFrameScreenCoordinates = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
    let keyboardEndFrame = self.view.convert(keyboardEndFrameScreenCoordinates, to: view.window)

    if notification.name == Notification.Name.UIResponder.keyboardWillHideNotification {
        textView.contentInset = UIEdgeInsets.zero
    } else {
        textView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardEndFrame.height, right: 0)
        textView.scrollIndicatorInsets = textView.contentInset
    }

    textView.scrollRangeToVisible(textView.selectedRange)
}

1 个答案:

答案 0 :(得分:1)

尝试一下:

if notification.name == UIResponder.keyboardWillHideNotification {

...