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

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

概述无法转换表达式的类型’CGRect’以键入’NSCopying!’在迅速 我试图在 swift文件中实现键盘通知. //在发送UIKeyboardDidShowNotification时调用. func keyboardWasShown(aNotification :NSNotification) { var info = aNotification.userInfo 无法转换表达式的类型’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    }}
总结

以上是内存溢出为你收集整理的无法转换表达式的类型’CGRect’以键入’NSCopying!’在迅速全部内容,希望文章能够帮你解决无法转换表达式的类型’CGRect’以键入’NSCopying!’在迅速所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1009490.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存