Yosemite のサイドバーには、半透明の「鮮やかな」背景があります。10.10/Xcode 6 でそのようなビューを作成するにはどうすればよいですか?
そのような背景を教えてもらえますか?「ソースリスト」ハイライトスタイルを指定すると、デフォルトでそのような背景になることがわかりましたNSOutlineView
が、Calendar.app のサイドバーは NSOutlineView ではないようです。
Yosemite のサイドバーには、半透明の「鮮やかな」背景があります。10.10/Xcode 6 でそのようなビューを作成するにはどうすればよいですか?
そのような背景を教えてもらえますか?「ソースリスト」ハイライトスタイルを指定すると、デフォルトでそのような背景になることがわかりましたNSOutlineView
が、Calendar.app のサイドバーは NSOutlineView ではないようです。
OSX オペレーティング システムの Yosemite バージョンの導入により、Apple はVibrancyと呼ばれる新しいモードを導入しました。これは光拡散ぼかしで、Cocoa ウィンドウおよびウィンドウ コンポーネントに適用されます。シャワーのドアから覗くようなもので、NSVisualEffectView
. Appleは、この効果についてここで説明しています。
このカテゴリは NSView で使用します。鮮やかにしたいビューを呼び出すだけです。Yosemite 以前との後方互換性もあります。(プレヨセミテの方は効果が見られません)
@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 からの詳細な手順は次のとおりです…</p>
AppKit.frameworkを Project Settings > Build Phases > Link Binary with Librariesに追加して、NSVisualEffectView を認識できるようにします。
ウィンドウ自体ではなく、メイン ウィンドウのデフォルト ビューのアウトレットデリゲートをAppDelegate.m または AppDelegate.mm ファイルに作成します。(初めての方は、このチュートリアルをお読みください。) ここでは、これを として名前を付けたと仮定します。これは、コードで としてアドレス指定できます。mainview
_mainview
プロジェクトにカテゴリを含めます。初めての方は、 AppDelegate.m または AppDelegate.mm ファイル@implementation
の任意の行の前にカテゴリを追加してください。
AppDelegate.mまたは AppDelegate.mm ファイル内のクラス メソッド@implementation AppDelegate
内に、次のコード行を追加します。applicationDidFinishLaunching
[_mainview insertVibrancyViewBlendingMode:NSVisualEffectBlendingModeBehindWindow];
最終的な効果として、タイトルバーの下のウィンドウ全体、または必要な部分 (サイドバーなど) のみに、この鮮やかな効果が表示されます。
を使用するだけNSVisualEffectView
です。次のように、フィールドを使用してさらに微調整できます。
class MyFancyView: NSVisualEffectView {
func myConfigureFunc() {
// Use blendingMode to specify what exactly is blurred
blendingMode = .behindWindow // [DEFAULT] ignores in-window content and only blurs content behind the window
blendingMode = .withinWindow // ignores content behind the window and only blurs in-window content behind this view
// Use material to specify how the blur draws (light/dark/etc.)
material = .light // The Vibrant Light look we see in countless Apple apps' sidebars, Sierra notification center, etc.
material = .dark // The Vibrant Dark look we all know and love from HUDs, Launchpad, Yosemite & El Capitan notification center, etc.
material = .appearanceBased // [DEFAULT] Automatically uses .light or .dark, depending on the view's appearance field
material = .titlebar // The material the system uses in titlebars. Designed to be used with blendingMode = .withinWindow
material = .selection // A special material for selection. The material will vary depending on the effectiveAppearance, active state, and emphasized state.
if #available(OSX 10.11, *) {
// Materials introduced in 10.11 (El Capitan)
material = .mediumLight // Not quite as light as .light
material = .ultraDark // Much darker than .dark
material = .menu // The material the system uses for menus
material = .popover // The material the system uses for popovers
material = .sidebar // The material the system uses for sidebars
}
// Use state to specify when the visual effect appears
state = .active // Always show the visual effect
state = .inactive // Never show the visual effect (behaves like a normal view)
state = .followsWindowActiveState // [DEFAULT] Active when window is active, not when window is not
}
}
詳細については、Apple の公式ビデオをご覧ください: WWDC 2014 セッション 220