【发布时间】:2016-12-17 09:28:04
【问题描述】:
我删除了AppDelegate.swift中的@UIApplicationMain并写了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
}
}
【问题讨论】:
标签: swift events key uikeycommand