Objective c OSX上的圆形网络视图与Cordova?
我正在用创建一个MacOSX应用程序。我已经尝试实现了我见过的所有关于我的应用程序有圆角的解决方案,但都不起作用。最后一个资源将删除阴影和创建CSS的角落,但我真的不喜欢这种方法 因此,负责创建webview并加载它。这就是我的方法:Objective c OSX上的圆形网络视图与Cordova?,objective-c,macos,cordova,webview,Objective C,Macos,Cordova,Webview,我正在用创建一个MacOSX应用程序。我已经尝试实现了我见过的所有关于我的应用程序有圆角的解决方案,但都不起作用。最后一个资源将删除阴影和创建CSS的角落,但我真的不喜欢这种方法 因此,负责创建webview并加载它。这就是我的方法: - (void) awakeFromNib { _commandDelegate = [[CDVCommandDelegateImpl alloc] initWithViewController:self]; self.webViewDelegat
- (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]];
}
}
这是我用来显示面板的代码:
- (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的角设置为圆角。我只是在
applicationdFinishLaunching
方法中写的:
self.webView.wantsLayer = YES;
self.webView.layer.cornerRadius = 50.0f;
self.webView.layer.masksToBounds = YES;
[self.webView.mainFrame.frameView setAllowsScrolling:NO];
正如你所看到的,舍入是有效的,但在角落里也有白色的地方,我不知道如何处理它们嗨,你能在你的问题中解释一下你得到了什么结果而不是“似乎不起作用”吗?我想很清楚:我在框架中没有看到任何舍入的角落,它不是。我现在不知道你在视图中看到了什么,也不知道它可能有什么问题。当结果不能按预期工作时,您可以得到各种各样的结果。说明您实际看到的、未看到的以及任何错误有助于我们帮助您了解可能发生的情况。细节越多越好。例如webView显示为正常,但没有圆角。没有报告任何错误。滚动等时的网络视图行为是正常的。@AntonioLaguna尝试将此代码移动到viewDidLoad并添加self.webView.layer.masksToBounds=YES;在self.webView.layer.cornerRadius=10之后@RobertoFerraz这个代码到底是什么?是从NIB唤醒的
还是另一个maskToBounds
似乎也不起作用。请尝试以下操作:[self.webView setDrawsBackground:NO]代码>
self.webView.wantsLayer = YES;
self.webView.layer.cornerRadius = 50.0f;
self.webView.layer.masksToBounds = YES;
[self.webView.mainFrame.frameView setAllowsScrolling:NO];