【发布时间】:2014-08-02 04:47:59
【问题描述】:
这是我目前尝试过的
func onKeyboardRaise(notification: NSNotification) {
var notificationData = notification.userInfo
var duration = notificationData[UIKeyboardAnimationDurationUserInfoKey] as NSNumber
var frame = notificationData[UIKeyboardFrameBeginUserInfoKey]! as NSValue
var frameValue :UnsafePointer<(CGRect)> = nil;
frame.getValue(frameValue)
}
但我似乎总是在frame.getValue(frameValue) 崩溃。
这有点令人困惑,因为UIKeyboardFrameBeginUserInfoKey 的文档说它返回一个CGRect 对象,但是当我在控制台中记录frame 时,它会显示类似NSRect {{x, y}, {w, h}} 的内容。
【问题讨论】:
-
它不是一个不安全的指针,所以不要把它变成一个!只需阅读 NSValue 上的文档:developer.apple.com/library/ios/documentation/uikit/reference/… 这与在 Objective-C 中执行此操作没有什么不同。无需为自己做简单的事情。