0
Я удалил @UIApplicationMain
в AppDelegate.swift
и написал main.swift
, как показано ниже, но программа все еще не может выполнить функцию keyPressed
. Но выполняет print("send event2")
каждый keydown.Как перехватить ключевое событие быстрого приложения iOS?
Как уволить 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
}
}
"Действие: #selector (KeyPressed (отправитель :))" вместо " action: Selector (("keyPressed:")) " – baileymiller2017