UIKeyCommand
我在 Swift中遇到了问题。我有两个UIViewVontroller
和。我正在使用此代码打开:ProjectsViewController
ViewController
ViewController
ProjectsViewController
let editor = self.storyboard?.instantiateViewController(withIdentifier: "editor")
self.present(editor!, animated: true, completion: nil)
在我的ProjectsViewController
课上,我有一些UIKeyCommands
:
override var keyCommands: [UIKeyCommand]?
{
if #available(iOS 9.0, *)
{
return [
UIKeyCommand(input: "n", modifierFlags: .command, action: #selector(projectWizard), discoverabilityTitle: "Create new project"), UIKeyCommand(input: "t", modifierFlags: .command, action: #selector(toolsAction), discoverabilityTitle: "Open Tools"), UIKeyCommand(input: ",", modifierFlags: .command, action: #selector(settingsAction), discoverabilityTitle: "Open Settings"), UIKeyCommand(input: "i", modifierFlags: .command, action: #selector(aboutAction), discoverabilityTitle: "About")
]
}
else
{
return nil
}
}
在ViewController
我还有另一个:
override var keyCommands: [UIKeyCommand]?
{
if #available(iOS 9.0, *)
{
return [
UIKeyCommand(input: "n", modifierFlags: .command, action: #selector(addFileAction), discoverabilityTitle: "New file"), UIKeyCommand(input: "r", modifierFlags: .command, action: #selector(runProject), discoverabilityTitle: "Build and run"), UIKeyCommand(input: "w", modifierFlags: .command, action: #selector(closeProject), discoverabilityTitle: "Close window")
]
}
else
{
return nil
}
}
当我的应用程序出现ProjectsViewController
时,我在 iPad 上按下了 cmd 以显示 Discoverability,它显示了 的组合ProjectsViewController
,但是在我打开ViewController
并按下 cmd 后,Discoverability 显示了ProjectsViewController
和的组合ViewController
。如何为每个班级分开键盘快捷键?感谢您的关注。