gpt4 book ai didi

ios - Xcode6-Beta3 更新后,无法使用 Swift 访问键盘信息

转载 作者:行者123 更新时间:2023-11-28 09:20:58 27 4
gpt4 key购买 nike

在 xcode6-beta3 更新之前,我能够通过键盘通知访问键盘的框架 (CGRect)。但是现在我尝试获得的每个值都是“nil”

通知码

notificationCenter.addObserver(self, selector: "keyboardWillAppear:", name: UIKeyboardWillShowNotification, object: nil)

keyboardWillAppear 功能代码

func keyboardWillAppear(notification: NSNotification){
var keyboardSize = notification.userInfo[UIKeyboardFrameBeginUserInfoKey]!.frame.size.height
println(keyboardSize)
}

我尝试打印的任何值都为零:

tried: .frame
.size.height
.size

任何指针(指针,哈哈)或帮助将不胜感激

最佳答案

您的代码调整如下:

func shrinkTextView (ncMessage: NSNotification) {

var keyboardSize: AnyObject? = ncMessage.userInfo[UIKeyboardFrameBeginUserInfoKey]
println("\(keyboardSize?)")

}

...打印

可选(NSRect:{{0, 568}, {320, 216}})

您是否正确添加了观察者?我试过这样:

 NSNotificationCenter.defaultCenter().addObserver(
self, selector: "shrinkTextView:",
name: "UIKeyboardWillShowNotification", object: nil)

关于ios - Xcode6-Beta3 更新后,无法使用 Swift 访问键盘信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24643274/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com