我有
func keyboardWillShow(aNotification: NSNotification) {
//Collect information about keyboard using its notification.
let info = aNotification.userInfo
let duration = (info[UIKeyboardAnimationDurationUserInfoKey] as NSValue) as Double
let curve : AnyObject? = info[UIKeyboardAnimationCurveUserInfoKey]
let kbFrame : AnyObject? = (info[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue().size
}
如何在没有
的情况下阅读这些内容“[NSObject:AnyObject]?没有名为'subscript'的成员”错误?
在xCode的beta版本中,这已经奏效了,但是从 xCode 6.1 开始,它已经无法正常运行了。
答案 0 :(得分:1)
userInfo是可选的Dictionary,因此您可以使用可选绑定来解包值。而CGSize是一个结构,而不是一个对象,所以将AnyObject更改为CGSize。
if let info = aNotification.userInfo {
let duration = (info[UIKeyboardAnimationDurationUserInfoKey] as NSValue) as Double
let curve : AnyObject? = info[UIKeyboardAnimationCurveUserInfoKey]
let kbFrame: CGSize = (info[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue().size
}