首页 > 解决方案 > 如何使用自定义 UIWindow 来覆盖 sendEvent 函数?

问题描述

SNWindow是我使用自定义委托创建的自定义类,它覆盖了sendEvent函数。

在以前的 iOS 版本中(没有 SceneDelegate 时),我曾经在 AppDelegate.h 中插入此代码:

@property (strong, nonatomic) SNWindow *window;

AppDelegate.m 中的这段代码:

- (SNWindow *)window {
    
    static SNWindow *window = nil;
    
    if (!window) {
        
        window = [[SNWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    }
    
    return window;
}

而 ViewController.m 中的这段代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    appDelegate.window.delegate = self;

    appDelegate.window.view = self.view;
}

不幸的是,这不再起作用了。我尝试更改 SceneDelegate 的 UIWindow 但屏幕上没有加载任何内容,只是黑屏。

标签: iosobjective-cappdelegatesceneuiwindow

解决方案


推荐阅读