我删除了@UIApplicationMain
inAppDelegate.swift
并写了main.swift
如下,但程序仍然无法触发keyPressed
功能。但执行print("send event2")
每个按键。
如何开火keyPressed
功能?这个程序有问题吗?
import UIKit
import Foundation
class TApplication: UIApplication {
override func sendEvent(_ event: UIEvent!) {
super.sendEvent(event)
}
override var keyCommands: [UIKeyCommand]? {
print("send event2") // this is an example
return [
UIKeyCommand(input: "1", modifierFlags: [], action: Selector(("keyPressed:")), discoverabilityTitle: “1”),
UIKeyCommand(input: "2", modifierFlags: .shift, action: Selector("keyPressed:"), discoverabilityTitle: “2”)]
]
}
func keyPressed(sender: UIKeyCommand) {
print("keypressed event !!!!!!!!") // this is an example
}
}