2011-07-30 85 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];

提前感谢

回答

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的子视图。当然,在这种情况下,你必须自己做所有的布局。

+0

完美!还有一件事,即使窗口改变了大小,我如何将子视图居中,并让它保持在中心位置? – GarethPrice

+0

'INAppStoreWindow'可以在' - (void)_layoutTrafficLightsAndContent'中工作,我将其子类化并重置子视图的边界。 –