2010-11-29 9 views
5

iTunesのスタイルに従ってウィンドウを作成するためのCocoa用のオープンソースライブラリはありますか?これは、ウィンドウコントロールが垂直の代わりに、水平方向にレイアウトされている。iTunesスタイルのNSWindowサブクラスですか?

sample iTunes window

私はそれは、省スペースとウィンドウタイトルを必要としない、ユーティリティ型アプリケーションに適して見つけます。

+11

私はそれが迷惑とAppleのデザインガイドラインに違反見つけます。私は彼らがそれをやり続けないことを本当に望む。それは悪い例を設定します。確かに、私は同じように願っています。 – JeremyP

答えて

8

この素早く離れてハッキングNSWindowのデリゲートは、作業を開始する必要があります

//VerticalTrafficLightsWindowDelegate.h 

#import <Cocoa/Cocoa.h> 

@interface VerticalTrafficLightsWindowDelegate : NSObject <NSWindowDelegate> { 
    NSWindow *window; 
} 

@property (assign) IBOutlet NSWindow *window; 

- (void)verticalizeButtonsForWindow:(NSWindow *)aWindow; 

@end 

//VerticalTrafficLightsWindowDelegate.m 

#import "VerticalTrafficLightsWindowDelegate.h" 

@implementation VerticalTrafficLightsWindowDelegate 

@synthesize window; 

- (void)awakeFromNib { 
    [self verticalizeButtonsForWindow:window]; 
} 

- (void)windowDidResize:(NSNotification *)notification { 
    [self verticalizeButtonsForWindow:window]; 
} 

- (void)verticalizeButtonsForWindow:(NSWindow *)aWindow { 
    NSArray *contentSuperViews = [[[aWindow contentView] superview] subviews]; 

    NSView *closeButton = [contentSuperViews objectAtIndex:0]; 
    NSRect closeButtonFrame = [closeButton frame]; 

    NSView *minimizeButton = [contentSuperViews objectAtIndex:2]; 
    NSRect minimizeButtonFrame = [minimizeButton frame]; 

    NSView *zoomButton = [contentSuperViews objectAtIndex:1]; 
    NSRect zoomButtonFrame = [zoomButton frame]; 

    [minimizeButton setFrame:NSMakeRect(closeButtonFrame.origin.x, closeButtonFrame.origin.y - 20.0, minimizeButtonFrame.size.width, minimizeButtonFrame.size.height)]; 
    [zoomButton setFrame:NSMakeRect(closeButtonFrame.origin.x, closeButtonFrame.origin.y - 40.0, zoomButtonFrame.size.width, zoomButtonFrame.size.height)]; 
} 

@end 

は、しかし、私はちょうどJeremyPのように、私は唯一のAppleは、このいずれかのOS Xの広い

+0

それらのコントロールは醜いです。 –

+0

これは動作しますが、かなり醜いです。また、タイトルバーのサイズを拡張する必要がありますが、iTunesがNSToolbarに相当するCocoaに相当するものを使用していると思われます。しかし、我々はまた、小さいサイズの信号を必要とします;) –

+0

iTunesと視覚的にマッチさせるには、明らかに統一テクスチャウィンドウを使用する必要があります。さらに、iTunesのウィンドウUIがどのように設定されているか(UIブラウザ)を見れば、iTunesにはツールバーがまったく使用されていないことがわかります!とにかく、これらのトラフィックボタンはツールバーの要素であるべきではありません。それらはウィンドウの上位機能であり、内容とは関係ありません(対ツールバーアイコン)。 (大丈夫、ズームはコンテンツに関連していますが、あなたはその点を知っていますか?)) – Regexident

1

おそらく、NSWindow、NSViewをサブクラス化して、ウィンドウとボタンを自分で描画する必要があります。

ああ、ちょうどあなたがカスタム図面を行うかなり重要な細部を失うと付け加えたいと思います。描画がメインスレッドで行われているため、メインスレッドの実行をブロックしている重大な重要なタスクをしばらく実行すると、メインスレッドがビジーになる可能性があるため、ユーザーはウィンドウを移動することができず、 。

他のスレッドでマウスのリスニングイベントを実装しない限り、そこに描画を行い、フォーカスをロックします...私の意図したことは、本当にこれがあなたのアプリをもっと良くすると思わない限り気にしないでください:)

0

だけを広めることはないだろう望むことができると言うようになりました@Regexidentの '新しいMacOSのためのs。新しいmacOS UIのビュー階層が変更されたため、元のバージョンは機能しません。変更されたコードは次のよう(MacOSの10.13で動作します)です:

- (void)verticalizeButtonsForWindow:(NSWindow *)aWindow { 
    // New view hierarchy. 
    NSView *titleBarContainerView = aWindow.contentView.superview.subviews[1]; 
    titleBarContainerView.frame = NSMakeRect(titleBarContainerView.frame.origin.x, titleBarContainerView.frame.origin.y - 60.0 + titleBarContainerView.frame.size.height, titleBarContainerView.frame.size.width, 60.0); 
    NSView *titleBarView = titleBarContainerView.subviews[0]; 
    titleBarView.frame = NSMakeRect(0.0, 0.0, titleBarView.frame.size.width, 60.0); 
    NSArray *titleBarSubviews = titleBarView.subviews; 

    NSView *closeButton = [titleBarSubviews objectAtIndex:0]; 
    NSRect closeButtonFrame = [closeButton frame]; 

    NSView *minimizeButton = [titleBarSubviews objectAtIndex:2]; 
    NSRect minimizeButtonFrame = [minimizeButton frame]; 

    NSView *zoomButton = [titleBarSubviews objectAtIndex:1]; 
    NSRect zoomButtonFrame = [zoomButton frame]; 

    // Coordinate changed: add instead of minus. 
    [minimizeButton setFrame:NSMakeRect(closeButtonFrame.origin.x, closeButtonFrame.origin.y + 20.0, minimizeButtonFrame.size.width, minimizeButtonFrame.size.height)]; 
    [zoomButton setFrame:NSMakeRect(closeButtonFrame.origin.x, closeButtonFrame.origin.y + 40.0, zoomButtonFrame.size.width, zoomButtonFrame.size.height)]; 
} 

結果のスクリーンショット: enter image description here

関連する問題