3
閱讀http://nshipster.com/uikeycommand/之後,我想使用箭頭鍵將標籤之間的導航添加到我的應用程序。但我cuold沒有設法接收UITabBarController內的按鍵。下面的相同代碼塊在UIViewController中工作,但在UITabBarController中工作。UITabBarController canBecomeFirstResponder方法沒有被調用
當我試圖調試時,甚至沒有調用,UITabBarController的canBecomeFirstResponder重寫。我沒有在蘋果的文檔中找到有用的東西。欣賞任何使問題清楚的信息。
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let firstResponderResult = self.becomeFirstResponder()
println("became first responder \(firstResponderResult)")
}
override func canBecomeFirstResponder() -> Bool {
return true
}
override var keyCommands: [AnyObject]? {
return [
UIKeyCommand(input: UIKeyInputRightArrow, modifierFlags: UIKeyModifierFlags.allZeros, action: "rightArrowClicked:"),
UIKeyCommand(input: UIKeyInputLeftArrow, modifierFlags: UIKeyModifierFlags.allZeros, action: "leftArrowClicked:")
]
}
func rightArrowClicked(sender: UIKeyCommand) {
let currentIndex = selectedIndex;
if (currentIndex < viewControllers!.count - 1) {
selectedIndex = currentIndex + 1;
}
}
func leftArrowClicked(sender: UIKeyCommand) {
let currentIndex = selectedIndex;
if (currentIndex > 0) {
selectedIndex = currentIndex - 1;
}
}
這項工作適合您嗎?在我的情況下,最初添加'canBecomeFirstResponder'工作,但鍵盤用於移動到不同的UIViewController(它也具有相同的'canBecomeFirstResponder'和keyCommands)後,第二個視圖控制器不響應鍵盤輸入。它似乎不會將firstResponder狀態轉移到第二個VC。你的情況也是這樣嗎? –
不幸的是,我的情況和你一樣。我認爲,唯一能解決問題的方法就是回答下面的問題,但我沒有嘗試過,只是放棄了實現這個功能。 – mehmet6parmak