在AppDelegate的文件中
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
这样进行了注解
那么问题来了,如果想要实现自己的main文件该怎么办呢?
import Foundation
import UIKit
class MyApplication: UIApplication {
override func sendEvent(_ event: UIEvent) {
super.sendEvent(event)
print(event)
}
}
UIApplicationMain(
CommandLine.argc,
UnsafeMutableRawPointer(CommandLine.unsafeArgv)
.bindMemory(
to: UnsafeMutablePointer<Int8>.self,
capacity: Int(CommandLine.argc)),
NSStringFromClass(MyApplication.self),
NSStringFromClass(AppDelegate.self)
)
我这里给出一种实现方式注意:MyApplication的sendEvent在我点击手机屏幕的时候会执行两遍
<UITouchesEvent: 0x6180000e4f80> timestamp: 37129.3 touches: {(
<UITouch: 0x7fdd03701170> phase: Began tap count: 1 force: 0.000 window: <UIWindow: 0x7fdd06009f10; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000051d90>; layer = <UIWindowLayer: 0x60000002afe0>> view: <UIView: 0x7fdd03403160; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x61800002b2c0>> location in window: {215, 247.5} previous location in window: {215, 247.5} location in view: {215, 247.5} previous location in view: {215, 247.5}
)}
<UITouchesEvent: 0x6180000e4f80> timestamp: 37130.9 touches: {(
<UITouch: 0x7fdd03701170> phase: Ended tap count: 0 force: 0.000 window: <UIWindow: 0x7fdd06009f10; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000051d90>; layer = <UIWindowLayer: 0x60000002afe0>> view: <UIView: 0x7fdd03403160; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x61800002b2c0>> location in window: {215, 247.5} previous location in window: {215, 247.5} location in view: {215, 247.5} previous location in view: {215, 247.5}
)}
这是 两遍打印的结果,从中可以看出这是点击开始 和 结束的两个事件