32

Yosemite のサイドバーには、半透明の「鮮やかな」背景があります。10.10/Xcode 6 でそのようなビューを作成するにはどうすればよいですか?

そのような背景を教えてもらえますか?「ソースリスト」ハイライトスタイルを指定すると、デフォルトでそのような背景になることがわかりましたNSOutlineViewが、Calendar.app のサイドバーは NSOutlineView ではないようです。

ここに画像の説明を入力

4

3 に答える 3

20

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>

使い方

  1. AppKit.frameworkを Project Settings > Build Phases > Link Binary with Librariesに追加して、NSVisualEffectView を認識できるようにします。

  2. ウィンドウ自体ではなく、メイン ウィンドウのデフォルト ビューのアウトレットデリゲートAppDelegate.m または AppDelegate.mm ファイルに作成します。(初めての方は、このチュートリアルをお読みください。) ここでは、これを として名前を付けたと仮定します。これは、コードで としてアドレス指定できます。mainview_mainview

  3. プロジェクトにカテゴリを含めます。初めての方は、 AppDelegate.m または AppDelegate.mm ファイル@implementationの任意の行の前にカテゴリを追加してください。

  4. AppDelegate.mまたは AppDelegate.mm ファイル内のクラス メソッド@implementation AppDelegate内に、次のコード行を追加しますapplicationDidFinishLaunching

[_mainview insertVibrancyViewBlendingMode:NSVisualEffectBlendingModeBehindWindow];
  1. ここで、コードを追加してウィンドウの他の要素と、ウィンドウ自体に半透明性を与える方法を学ぶ必要があります。その半透明性により、必要に応じてこの効果がウィンドウ コンポーネントに透けて見えるようになります。これについては、こちらで説明しています

最終的な効果として、タイトルバーの下のウィンドウ全体、または必要な部分 (サイドバーなど) のみに、この鮮やかな効果が表示されます。

于 2014-10-04T16:00:24.640 に答える
2

を使用するだけ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

于 2017-01-04T21:01:21.953 に答える