在优胜美地,侧边栏具有半透明的“充满活力”的背景。如何在10.10 / Xcode 6中创建类似的 View ?
我可以给这样的背景有什么看法吗?我发现当您将NSOutlineView
赋予“源列表”突出显示样式时,它会默认使用这种背景,但是Calendar.app的侧边栏似乎不是NSOutlineView,所以我想知道是否有通用的解决方案。
最佳答案
随着OSX操作系统的优胜美地版本的推出,苹果公司对 cocoa 窗和窗组件引入了一种称为活力的新模式,即光扩散模糊。有点像透过淋浴门看,并使用NSVisualEffectView
。苹果explains this effect here。
我在NSView上使用此类别。
只需调用您想使其充满活力的 View 即可。
它也与优胜美地以前的版本向后兼容。 (如果您之前有优胜美地,将看不到效果)
@implementation NSView (HS)
-(instancetype)insertVibrancyViewBlendingMode:(NSVisualEffectBlendingMode)mode
{
Class vibrantClass=NSClassFromString(@"NSVisualEffectView");
if (vibrantClass)
{
NSVisualEffectView *vibrant=[[vibrantClass alloc] initWithFrame:self.bounds];
[vibrant setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
// uncomment for dark mode instead of light mode
// [vibrant setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameVibrantDark]];
[vibrant setBlendingMode:mode];
[self addSubview:vibrant positioned:NSWindowBelow relativeTo:nil];
return vibrant;
}
return nil;
}
@end
@Volomike的详细说明如下……如何使用
mainview
,然后在代码中将其命名为_mainview
。@implementation
行之前添加类别。@implementation AppDelegate
中,在applicationDidFinishLaunching
类方法内,添加以下代码行:[_mainview insertVibrancyViewBlendingMode:NSVisualEffectBlendingModeBehindWindow];
现在的净效果是,标题栏下方的整个窗口,或仅您想要的部分(例如侧栏)将显示这种活力效果。
关于macos - 如何创建具有半透明/模糊背景的优胜美地风格的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24023183/