此行let userInfo = notification.userInfo as! NSDictionary
我得到一個警告:Cast from '[NSObject : AnyObject]?' to unrelated type 'NSDictionary' always fails
從'[NSObject:AnyObject]中投射?'無關型「的NSDictionary」總是失敗
我嘗試使用let userInfo = notification.userInfo as! Dictionary<NSObject: AnyObject>
取代let userInfo = notification.userInfo as! NSDictionary
。但是我收到一個錯誤:Expected '>' to complete generic argument list
。如何解決警告。
的Xcode 7.1 OS X約塞米蒂
這是我的代碼:
func keyboardWillShow(notification: NSNotification) {
let userInfo = notification.userInfo as! NSDictionary //warning
let keyboardBounds = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
let duration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue
let keyboardBoundsRect = self.view.convertRect(keyboardBounds, toView: nil)
let keyboardInputViewFrame = self.finishView!.frame
let deltaY = keyboardBoundsRect.size.height
let animations: (()->Void) = {
self.finishView?.transform = CGAffineTransformMakeTranslation(0, -deltaY)
}
if duration > 0 {
} else {
animations()
}
}
只使用Swift原生字典 –
我嘗試使用'let userInfo = notification.userInfo as! Dictionary'但它是錯誤的,我得到一個錯誤。 –
rose
爲什麼要輸入鑄件? – vadian