加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

无法转换表达式的类型’CGRect’以键入’NSCopying!’在迅速

发布时间:2020-12-14 04:47:14 所属栏目:百科 来源:网络整理
导读:无法转换表达式的类型’CGRect’以键入’NSCopying
无法转换表达式的类型’CGRect’以键入’NSCopying!’在迅速
我试图在 swift文件中实现键盘通知.

//在发送UIKeyboardDidShowNotification时调用.

func keyboardWasShown(aNotification :NSNotification)
    {
        var info = aNotification.userInfo
        var kRect:CGRect = info[UIKeyboardFrameBeginUserInfoKey] as CGRect
        var kbSize:CGSize = kRect.size

但不确定为什么我会收到此错误?

解决方法

你无法将你从字典中提取的价值转发给CGRect.它是一个NSValue对象,因此您可以使用CGRectValue()轻松地从中获取rect值.这应该可以满足您的需求.

func keyboardWasShown(aNotification: NSNotification) {
    let info = aNotification.userInfo

    if let rectValue = info[UIKeyboardFrameBeginUserInfoKey] as? NSValue {
        let kbSize:CGSize = rectValue.CGRectValue().size
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读