账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    一个 Cocoa 程序 WebView 的问题
    66
    0

    画一个全屏的 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 的网络限制)

    求解

    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 韩明玄 普通会员 1楼
      { "error": "Failed to generate content." }
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部