一个 Cocoa 程序 WebView 的问题

画一个全屏的 NSWindow ,并在其中画一个全屏的 WebView ,然后我发现鼠标事件在最底部一行无法触发,下面是一个 Demo:

//
//  AppDelegate.m
//  screenEdgeDemo
//
//  Created by SpringHack on 2017/12/12.
//  Copyright © 2017年 Dosk. All rights reserved.
//

#import "AppDelegate.h"
#import "Webkit/WebKit.h"

@interface WebInspector : NSObject  { WebView *_webView; }
- (id)initWithInspectedWebView:(WebView *)webView;
- (void)detach:     (id)sender;
- (void)show:       (id)sender;
- (void)showConsole:(id)sender;
@end


@interface AppDelegate () {
    __weak NSWindow* win;
    WebView* web;
}

@end

@implementation AppDelegate

- (void)openIns {
//    WebInspector *inspector = [[WebInspector alloc] initWithInspectedWebView:web];
//    [inspector detach:web];
//    [inspector showConsole:web];
    [[web windowScriptObject] evaluateWebScript:@"document.addEventListener('mousemove', (ev) => { document.body.innerHTML = `(${ev.x}, ${ev.y})`; });"];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    win = [[[NSApplication sharedApplication] windows] firstObject];
    [win setLevel:CGShieldingWindowLevel()];
    NSRect frame = [NSScreen mainScreen].frame;
    [win setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorFullScreenAuxiliary];
    [win setHasShadow:NO];
    [win setOpaque:NO];
    [win setStyleMask:NSWindowStyleMaskBorderless];
    [win setFrame:frame display:NO];
    web = [[WebView alloc] initWithFrame:frame];
    [win setContentView:web];
    NSURL* url = [NSURL URLWithString:@"https://www.dosk.win"];
    [[web mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
    [self performSelector:@selector(openIns) withObject:nil afterDelay:2];
}


- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}


@end

新建 Cocoa 程序粘贴到 AppDelegate.m 并引入 WebKit 可以测试(关掉 SandBox 的网络限制)

求解

阅读 2.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题