当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Rounded WebView on OSX with Cordova?

问题描述:

I'm creating a Mac OSX application with Cordova-osx. I've tried to implement all solutions I've seen about having rounded corners for my app but none of them work. Last resource will be removing the shadow and creating the corners with CSS but I don't really like that approach.

So, this is the file in charge of creating the webview and loading it. And this was my approach:

- (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]];

}

}

Which basically is adding this:

self.webView.layer.cornerRadius = 10;

self.webView.layer.opaque = NO;

This is the code I use to show the panel:

- (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];

}

But doesn't seem to be showing any rounded corners in the frame. Any ideas?

网友答案:

I still can't make suitable view because of white corners, but I made WebView's corners rounded. I wrote this just in applicationDidFinishLaunching method:

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

and as you can see rounding is works, but there also white places in corners, and I don't know how to deal with them

分享给朋友:
您可能感兴趣的文章:
随机阅读: