1

我删除了@UIApplicationMaininAppDelegate.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
    }
}
4

1 回答 1

0

我将'selector'修改为#selector(swift 3),终于解决了问题,可能是有bug

于 2016-12-18T01:17:53.510 回答