将工具栏添加到INAppStoreWindow

时间:2011-07-30 03:04:55

标签: objective-c cocoa nsview nstoolbar

我正在尝试向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];

非常感谢提前

1 个答案:

答案 0 :(得分:2)

INAppStoreWindow在窗口小部件和内容视图之间titleBarView狡猾:

<强> 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];
    }
}

NSToolbar不是NSView子类,它意味着与窗口本身一起工作,窗口本身被titleBarView遮挡。只是为了踢,在INAppStoreWindow.m中设置渐变颜色的alpha并运行应用程序;你可以看到“真正的”窗口仍在下面。

如果您已开始使用INAppStoreWindow,那么您最好的选择可能是使用您自己的自定义视图和按钮伪造工具栏并将其添加为titleBarView的子视图。当然,在这种情况下,你必须自己做所有的布局。