1
我在swift中有以下訂閱。我需要知道鍵盤何時會顯示以移動視圖。它編譯和按預期工作,但我不知道如何擺脫這個警告。 「目標C選擇器鍵盤顯示沒有方法」如何在訂閱NSNotifications時使用Objective C選擇器作爲參數?
// Subscribing class to recieve the notification
func subscribeToKeyboardNotifications() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow", name: UIKeyboardWillShowNotification, object: nil)
}
// Shifting view's frame up
func keyboardWillShow(notification: NSNotification) {
view.frame.origin.y -= getKeyboardHeight(notification)
}
// Getting keyboard height
func getKeyboardHeight(notification: NSNotification) -> CGFloat {
let userInfo = notification.userInfo
let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue // of CGRect
return keyboardSize.CGRectValue().height
}
在此先感謝您的任何建議!
請檢查這個答案,http://stackoverflow.com/questions/36366116/no-method-declared-with-objective-c-selector-for-notification-uikeyboardwillshow – Sandy