0

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;

ツールバーを作成し、コード内のアウトレットにリンクしましたが、NSView が必要なときに NSToolbar のクラスがある場合、どうすればそれをサブビューとして追加できますか?

これにより例外がスローされます。 [aWindow.titleBarView addSubview:toolbar];

よろしくお願いします

4

1 に答える 1

2

INAppStoreWindowtitleBarView、ウィンドウのウィジェットとコンテンツ ビューの間を次のように調整します。

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です。もちろん、その場合、すべてのレイアウトを自分で行う必要があります。

于 2011-07-30T04:05:28.977 に答える