Pregunta

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

enter image description here

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.

enter image description here

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:

enter image description here

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?

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top