可可:如何重新放置检查栏 [英] Cocoa: How to reposition Inspector Bar

查看:130
本文介绍了可可:如何重新放置检查栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个使用InspectorBar的NSTextView.但是,它只是像这样位于窗口的顶部:

My app has an NSTextView that uses the InspectorBar. However, it just sits at the top of the window like this:

我希望能够将其进一步定位在深色单杠上,该单杠目前是NSImageView. setFrame似乎没有效果.我该怎么办?

I want to be able to position it further down on the dark horizontal bar, which currently is an NSImageView. setFrame seems to have no effect. How can I do this?

我目前正在修复其他人对项目的实现.如下所示,他们能够移动检查器栏,并且没有使用NSToolbar.所以这一定是可能的.

I'm currently working on fixing someone else's implementation of a project. As you can see below, they were able to move the inspector bar, and they are not using NSToolbar. So it must be possible.

此人是如何做到这一点的:

Here's how this person achieved this:

- (void) addStyleBar
{
    NSArray* subviews = [self.window.contentView superview].subviews;
    [self.styleBar removeFromSuperview];

    [subviews enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop)
    {
        if (![obj isKindOfClass: [MainView class]])
        {
            self.styleBar = obj;
        }
    }];

    [self.styleBar setFrame: NSMakeRect(300.0f, 2.0f, CGRectGetWidth(self.styleBar.frame), CGRectGetHeight(self.bounds))];

    [self addSubview: self.styleBar];
}

但这对我的项目没有任何影响.

But this doesn't have any effect in my project.

如果我添加这样的约束:

EDIT 2: If I add a constraint like so:

    [[self.leftColumnVC.textView.window.contentView superview] addConstraint:[NSLayoutConstraint constraintWithItem:inspectorBarView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:formattingBarBackground attribute:NSLayoutAttributeTop multiplier:1 constant:0 ]];

在这里formattingBarBackground是在上面的第一张图片中看到的深灰色条.如果我这样做,我会得到:

Here formattingBarBackground is that dark gray bar seen in the first image above. If I do this I get this:

这很好,因为顶部的栏没有保留空间,并且通过迭代窗口的子视图,我仍然可以获得对NSInspectorBar的引用,因此它仍然存在,只是不可见.它是否隐藏在formattingBarBackground图像视图的后面?如果是这样,我该如何将它摆在最前面?

This is good because there is no reserved space for the bar at the top, and by iterating through the window's subviews I can still get a reference to NSInspectorBar, so it's still there, it's just not visible. Is it hiding behind the formattingBarBackground image view? If so how can I bring it to the front?

推荐答案

检查器栏位于窗口工具栏的下方.因此,您的问题是由"iTunes" UI的实现引起的.如果要在NSToolbar中将其实现为NSToolbarItems,则检查器栏会自动将其自身定位在其下方.

The Inspector Bar sits below the window's toolbar. So your problem is arising from your implementation of your "iTunes" UI. If you were to implement that as NSToolbarItems in an NSToolbar, then the Inspector Bar would automatically position itself below it.

没有API可以更改检查器栏的位置,因此,这是您最好的选择能够做到(没有实现自己的检查器栏).

There is no API to alter to the location of the Inspector Bar, so that's the best you'll be able to do (short of implementing your own inspector bar).

这篇关于可可:如何重新放置检查栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆