类型 'Notification.Name'(又名 'NSNotification.Name')没有成员 'UIResponder'
Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIResponder'
我有这个代码:
// MARK: - Listen for Keyboard Events and move the screen up upon keyboard is loaded
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange), name: UIResponder.keyboardWillHideNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
@objc func keyboardWillChange(notification: Notification) {
guard let keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else {
return
}
if notification.name == Notification.Name.UIResponder.keyboardWillShowNotification ||
notification.name == Notification.Name.UIKeyboardWillChangeFrame {
view.frame.origin.y = -keyboardRect.height
}else {
view.frame.origin.y = 0
}
}
但是Xcode11一直报错:
类型 'Notification.Name'(又名 'NSNotification.Name')在这一行中没有成员 'UIResponder':
if notification.name == Notification.Name.UIResponder.keyboardWillShowNotification ||
有人知道如何解决吗?
谢谢你的帮助!
使用
if notification.name == UIResponder.keyboardWillShowNotification ||
notification.name == UIResponder.keyboardWillChangeFrameNotification {
而不是
if notification.name == Notification.Name.UIResponder.keyboardWillShowNotification ||
notification.name == Notification.Name.UIKeyboardWillChangeFrame {
如错误中所见,它没有调用 Notification.Name UIResponder.
我有这个代码:
// MARK: - Listen for Keyboard Events and move the screen up upon keyboard is loaded
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange), name: UIResponder.keyboardWillHideNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillChange), name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
}
@objc func keyboardWillChange(notification: Notification) {
guard let keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else {
return
}
if notification.name == Notification.Name.UIResponder.keyboardWillShowNotification ||
notification.name == Notification.Name.UIKeyboardWillChangeFrame {
view.frame.origin.y = -keyboardRect.height
}else {
view.frame.origin.y = 0
}
}
但是Xcode11一直报错:
类型 'Notification.Name'(又名 'NSNotification.Name')在这一行中没有成员 'UIResponder':
if notification.name == Notification.Name.UIResponder.keyboardWillShowNotification ||
有人知道如何解决吗?
谢谢你的帮助!
使用
if notification.name == UIResponder.keyboardWillShowNotification ||
notification.name == UIResponder.keyboardWillChangeFrameNotification {
而不是
if notification.name == Notification.Name.UIResponder.keyboardWillShowNotification ||
notification.name == Notification.Name.UIKeyboardWillChangeFrame {
如错误中所见,它没有调用 Notification.Name UIResponder.