如何让Web View的一部分微透?
How To Make Part of Web View Slightly Translucent?
在Objective-C
和Mac OSX
Cocoa
中,有什么办法可以让DIV
在WebView
上稍微半透明,这样后面的桌面应用程序window 略微流血,但仅在 DIV
上而不是 WebView
?
的其余部分
或者我可以让整个 WebView 变成半透明的,但是除了一个 DIV
?
之外的所有 DIV
s 都关闭它
我有一个 WebView
加载网页。在网页中,我在左边有一个侧边栏,然后在右边有一个IFRAME
。我单击侧边栏上的项目,它们更改了右侧的 IFRAME
页面。我想把这个侧边栏做成半透明的。
在我的 AppDelegate.m
中,到目前为止,我的 HTML
和 BODY
标签设置为 background:none
,我的边栏设置为 background:rgba(0,0,0,0.5)
,但我最终看到的只是一个灰色的侧边栏背景。这就像 webview 本身想要确保它的背景设置为透明以外的颜色。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// note that _window and _wv are outlet properties to my window and webview widgets
[_window setBackgroundColor:[NSColor clearColor]];
[_window setOpaque:NO];
[_wv.layer setBackgroundColor:[NSColor clearColor].CGColor];
[_wv.layer setOpaque:NO];
}
是的,只需将 WebView
实例的 drawsBackground
属性 设置为 NO
,然后确保使用 CSS.
相关分步教程和示例:
http://stylekit.org/blog/2016/01/23/Chromeless-window/
设置半透明:
- 将您的 NSWindow 子类的 styleMask 设置为
NSFullSizeContentViewWindowMask
(这样半透明也会在标题栏区域可见,如果不这样做,标题栏区域将为空白)
- 设置
self.titlebarAppearsTransparent = true
(隐藏标题栏默认图形)
- 将下面的代码添加到您的 NSWindow 子类中:(您现在应该有一个半透明的 window)
.
let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 0, 0))//<---the width and height is set to 0, as this doesn't matter.
visualEffectView.material = NSVisualEffectMaterial.AppearanceBased//Dark,MediumLight,PopOver,UltraDark,AppearanceBased,Titlebar,Menu
visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow//I think if you set this to WithinWindow you get the effect safari has in its TitleBar. It should have an Opaque background behind it or else it will not work well
visualEffectView.state = NSVisualEffectState.Active//FollowsWindowActiveState,Inactive
self.contentView = visualEffectView/*you can also add the visualEffectView to the contentview, just add some width and height to the visualEffectView, you also need to flip the view if you like to work from TopLeft, do this through subclassing*/
在Objective-C
和Mac OSX
Cocoa
中,有什么办法可以让DIV
在WebView
上稍微半透明,这样后面的桌面应用程序window 略微流血,但仅在 DIV
上而不是 WebView
?
或者我可以让整个 WebView 变成半透明的,但是除了一个 DIV
?
DIV
s 都关闭它
我有一个 WebView
加载网页。在网页中,我在左边有一个侧边栏,然后在右边有一个IFRAME
。我单击侧边栏上的项目,它们更改了右侧的 IFRAME
页面。我想把这个侧边栏做成半透明的。
在我的 AppDelegate.m
中,到目前为止,我的 HTML
和 BODY
标签设置为 background:none
,我的边栏设置为 background:rgba(0,0,0,0.5)
,但我最终看到的只是一个灰色的侧边栏背景。这就像 webview 本身想要确保它的背景设置为透明以外的颜色。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// note that _window and _wv are outlet properties to my window and webview widgets
[_window setBackgroundColor:[NSColor clearColor]];
[_window setOpaque:NO];
[_wv.layer setBackgroundColor:[NSColor clearColor].CGColor];
[_wv.layer setOpaque:NO];
}
是的,只需将 WebView
实例的 drawsBackground
属性 设置为 NO
,然后确保使用 CSS.
相关分步教程和示例:
http://stylekit.org/blog/2016/01/23/Chromeless-window/
设置半透明:
- 将您的 NSWindow 子类的 styleMask 设置为
NSFullSizeContentViewWindowMask
(这样半透明也会在标题栏区域可见,如果不这样做,标题栏区域将为空白) - 设置
self.titlebarAppearsTransparent = true
(隐藏标题栏默认图形) - 将下面的代码添加到您的 NSWindow 子类中:(您现在应该有一个半透明的 window)
.
let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 0, 0))//<---the width and height is set to 0, as this doesn't matter.
visualEffectView.material = NSVisualEffectMaterial.AppearanceBased//Dark,MediumLight,PopOver,UltraDark,AppearanceBased,Titlebar,Menu
visualEffectView.blendingMode = NSVisualEffectBlendingMode.BehindWindow//I think if you set this to WithinWindow you get the effect safari has in its TitleBar. It should have an Opaque background behind it or else it will not work well
visualEffectView.state = NSVisualEffectState.Active//FollowsWindowActiveState,Inactive
self.contentView = visualEffectView/*you can also add the visualEffectView to the contentview, just add some width and height to the visualEffectView, you also need to flip the view if you like to work from TopLeft, do this through subclassing*/