Align the toolbar item to separate the display of content independent of the automatic layout options

I would like to align the button on the toolbar of the os x application with the split view position in the window, similar to the delete button in Apple Mail. How can this be done with auto-layout restrictions?

I found a hint in the apple documentation that you could use auto-layout restrictions ( https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/AutoLayoutConcepts/AutoLayoutConcepts.html ) he says that “restrictions can, with some restrictions, cross the hierarchy of views. For example, in the Mail application in OS X, the Delete button on the toolbar corresponds to the message table by default.” But this, unfortunately, is all that I could find.

I tried to create a restriction between the contents of the left splitView and the button:

NSView *button = self.toolbarItemButton.view;
NSView *leftPane = self.leftSplitContent;

[self.window.contentView addConstraints:[NSLayoutConstraint
    constraintsWithVisualFormat:@"[leftPane][button]"
    options:0 metrics:nil
    views:NSDictionaryOfVariableBindings(leftPane, button)]
];

, , , , : " - " ?

, , , , ( !) . , ... - .

+4
2

, , :

topLayoutGuide.

Ex

view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormats(
        ["H:|[toolbarShadow]|", "V:[topLayoutGuide][toolbarShadow(100)]"], 
views: viewDictionnary))

, topLayoutGuide

self.topLayoutGuide

+1

. OS X 10.11 El Capitan, NSLayoutGuide.

NSView "" . , subview splitview.

, NSLayoutAnchor. .

- (void) setUpToolbarItemConstrains {

// the view you want your toolbaritem to align to
NSView * refView = self.theOtherView.view;

// theToolbarItem is the outlet to the ToolbarItem
NSView * toolsView = self.theToolbarItem.view;

// You can also do this in Interface Builder
self.theToolbarItem.minSize = CGSizeMake(200.0f, 0.0f);
self.theToolbarItem.maxSize = CGSizeMake(600.0f, 100.0f);

toolsView.translatesAutoresizingMaskIntoConstraints = NO;

[toolsView.leadingAnchor constraintEqualToAnchor: refView.leadingAnchor].active = YES;

}

, .

+1

Source: https://habr.com/ru/post/1542783/


All Articles