objective-c – 使用Cordova在OSX上使用圆形WebView?

我正在用
Cordova-osx创建一个Mac OSX应用程序.我已经尝试实现我见过的有关我的应用程序的圆角的所有解决方案,但它们都不起作用.最后一个资源将删除阴影并使用CSS创建角落,但我真的不喜欢这种方法.

所以,this is the file负责创建webview并加载它.这是我的方法:

- (void) awakeFromNib
{
    _commandDelegate = [[CDVCommandDelegateImpl alloc] initWithViewController:self];
    self.webViewDelegate.viewController = self;

    NSURL* appURL = nil;
    NSString* loadErr = nil;

    if ([self.startPage rangeOfString:@"://"].location != NSNotFound) {
        appURL = [NSURL URLWithString:self.startPage];
    } else if ([self.wwwFolderName rangeOfString:@"://"].location != NSNotFound) {
        appURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", self.wwwFolderName, self.startPage]];
    } else {
        NSString* startFilePath = [self.commandDelegate pathForResource:self.startPage];
        if (startFilePath == nil) {
            loadErr = [NSString stringWithFormat:@"ERROR: Start Page at '%@/%@' was not found.", self.wwwFolderName, self.startPage];
            NSLog(@"%@", loadErr);
            self.loadFromString = YES;
            appURL = nil;
        } else {
            appURL = [NSURL fileURLWithPath:startFilePath];
        }
    }

    if (!loadErr) {
        NSURLRequest* appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
        self.webView.layer.cornerRadius = 10;
        self.webView.layer.opaque = NO;

        [[self.webView mainFrame] loadRequest:appReq];

    } else {
        NSString* html = [NSString stringWithFormat:@"<html><body> %@ </body></html>", loadErr];
        [[self.webView mainFrame] loadHTMLString:html baseURL:nil];
    }

    for (NSString* pluginName in self.startupPluginNames) {
        [self getCommandInstance:pluginName];
    }

    // initialize items based on settings

    BOOL enableWebGL = [[self.settings objectForKey:@"EnableWebGL"] boolValue];
    WebPreferences* prefs = [self.webView preferences];

    // Note that this preference may not be Mac App Store safe
    if (enableWebGL && [prefs respondsToSelector:@selector(setWebGLEnabled:)]) {
        [prefs performSelector:@selector(setWebGLEnabled:) withObject:[NSNumber numberWithBool:enableWebGL]];
    }
}

这主要是添加这个:

self.webView.layer.cornerRadius = 10;
self.webView.layer.opaque = NO;

这是我用来显示面板的代码:

- (void) showPanel
{

    NSPoint mouseLocation = [NSEvent mouseLocation];

    NSEnumerator *screenEnumerator = [[NSScreen screens] objectEnumerator];
    NSScreen *screen;
    while ((screen = [screenEnumerator nextObject]) && !NSMouseInRect(mouseLocation, screen.frame, NO))
        ;

    NSRect statusFrame = [[self.statusItem valueForKey:@"window"] frame];
    NSRect winFrame = [self.window frame];
    NSRect screenFrame = [screen frame];

    NSPoint p = NSMakePoint(statusFrame.origin.x, screenFrame.size.height + screenFrame.origin.y - 32);


    if ((p.x + winFrame.size.width) > (screenFrame.origin.x + screenFrame.size.width)) {
        p.x = screenFrame.origin.x + screenFrame.size.width - winFrame.size.width - 30;
    }

    [self.window setFrameTopLeftPoint:p];
    [self.window setIsVisible:YES];
    [NSApp activateIgnoringOtherApps:YES];
    [self.window makeKeyAndOrderFront:self];
}

但似乎没有在框架中显示任何圆角.有任何想法吗?

最佳答案 由于白角,我仍然无法制作合适的视图,但我将WebView的角设置为圆角.我在applicationDidFinishLaunching方法中写了这个:

self.webView.wantsLayer = YES;
self.webView.layer.cornerRadius = 50.0f;
self.webView.layer.masksToBounds = YES;
[self.webView.mainFrame.frameView setAllowsScrolling:NO];

你可以看到四舍五入是有效的,但角落里也有白色的地方,我不知道怎么处理它们

点赞