2011-07-30 11 views
0

ツールバーをINAppStoreWindowに追加しようとしています。INAppStoreWindowにツールバーを追加する

それは、この性質を持っています

/** The title bar view itself. Add subviews to this view that you want to show in 
the title bar (e.g. buttons, a toolbar, etc.). This view can also be set if 
you want to use a different styled title bar aside from the default one 
(textured, etc.). **/ 

@property (nonatomic, retain) NSView *titleBarView; 

ときに、私は、作成したツールバーを持っている、と私のコードでコンセントにリンクされているが、それはNSToolbarのクラスを持っている場合どのように私はサブビューとして追加することができますNSViewが必要ですか?

これは、例外がスローされます。事前に[aWindow.titleBarView addSubview:toolbar];

多くのおかげで、ウィンドウのウィジェットとコンテンツビューの間titleBarView

答えて

2

INAppStoreWindowイタチ:

INAppStoreWindow.m:

- (void)setTitleBarView:(NSView *)newTitleBarView 
{ 
if ((_titleBarView != newTitleBarView) && newTitleBarView) { 
    [_titleBarView removeFromSuperview]; 
    [_titleBarView release]; 
    _titleBarView = [newTitleBarView retain]; 

    // Configure the view properties and add it as a subview of the theme frame 
    NSView *contentView = [self contentView]; 
    NSView *themeFrame = [contentView superview]; 
    NSView *firstSubview = [[themeFrame subviews] objectAtIndex:0]; 
    [_titleBarView setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; 
    [self _recalculateFrameForTitleBarView]; 
    [themeFrame addSubview:_titleBarView positioned:NSWindowBelow relativeTo:firstSubview]; 
    [self _layoutTrafficLightsAndContent]; 
    [self display]; 
    } 
} 

NSToolbarNSViewサブクラスではありません。これはウィンドウ自体と連携して動作することを意味し、titleBarViewによって不明瞭になります。ちょうどキックのために、グラデーションカラーのアルファをINAppStoreWindow.mに設定し、アプリを実行します。あなたは "本当の"ウィンドウがまだそこにあるのを見ることができます。

INAppStoreWindowを使用して設定した場合は、ボタンを使用して独自のカスタムビューを使用してツールバーを偽装し、それをtitleBarViewのサブビューとして追加することをお勧めします。もちろん、その場合はレイアウトをすべて自分で行う必要があります。

+0

パーフェクト!もう1つだけ、どのように私はサブビューを中心にし、ウィンドウがサイズを変えても中央に留まるでしょうか? – GarethPrice

+0

'INAppStoreWindow'は' - (void)_layoutTrafficLightsAndContent'で動作します。サブクラス化してサブビューの境界をリセットします。 –

関連する問題