从文档:
let UIKeyboardframeEndUserInfoKey: String
描述
包含CGRect的NSValue对象的键,该键在屏幕坐标中标识键盘的末端框架
您的第二把钥匙:
let UIKeyboardAnimationDurationUserInfoKey: String
说明NSNumber对象的键,该键包含一个以秒为单位标识动画持续时间的double。
因此,您需要将第一个强制转换为NSValue,第二个强制转换为NSNumber:
func keyboardWillShow(_ notification: Notification) { print("keyboardWillShow") guard let userInfo = notification.userInfo else { return } keyboard = (userInfo[UIKeyboardframeEndUserInfoKey] as! NSValue).cgRectValue animaton = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doublevalue // your pre}


