gpt4 book ai didi

swift - 尝试获取键盘框架时出现下标错误?

转载 作者:行者123 更新时间:2023-11-30 14:05:55 25 4
gpt4 key购买 nike

我正在尝试从键盘通知中获取键盘框架。但我收到错误“[NSObject:AnyObject] 没有任何成员资格下标”

我正在使用以下代码。

  if keyboardNotification != nil {

let userInfo = keyboardNotification!.userInfo


let animationDuration: NSTimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as NSNumber).doubleValue()

let keyboardScreenBeginFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as NSValue).CGRectValue()

let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue()
}

最佳答案

notification.userInfo[NSObject : AnyObject]?

所以,试试这个

if let userInfo = keyboardNotification.userInfo {

let animationDuration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue()
let keyboardScreenBeginFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue()
let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()

}

关于swift - 尝试获取键盘框架时出现下标错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32424179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com