How to fix this issue with the UIResponder as not

2019-08-17 03:34发布

问题:

This question already has an answer here:

  • Error with notification names while converting code to Swift 4.2 2 answers

I'm making a NotePad application in Swift and I get the following issue:

type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIResponder'

Those are the lines of code I typed on:

@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:

Try this:

if notification.name == UIResponder.keyboardWillHideNotification {

...