Cocoa: How to reposition Inspector Bar

爱⌒轻易说出口 提交于 2019-12-12 01:12:49

问题


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

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?

EDIT: 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 ]];

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

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?


回答1:


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.

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).



来源:https://stackoverflow.com/questions/21100913/cocoa-how-to-reposition-inspector-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!