Hampus Tågerud Hampus Tågerud - 6 months ago 53
Objective-C Question

Using contentLayoutGuide for constraints

I´m trying to use a

with the new Vibrant theme in OSX 10.10 after watching the session from WWDC on advanced features of the new UI. My text view is not placed adjacent to the titlebar so I have made the content view fully sized so I can place the text view beneath title bar.

My problem is that I have a
between the text view and title bar which should be placed directly beneath the title bar but I can not get auto layout to do this for me. In the video they're giving this sample code using the new
property in

NSLayoutConstraint *topEdgeConstraint = [NSLayoutConstraint constraintWithItem:myView attribute: NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:window.contentLayoutGuide attribute:NSLayoutAttributeTop];

However I can not get this to work, whenever I try to install the constraint Xcode gives me

Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal.

I get that the window property used in the example is not in the subtree of the view since the view is placed inside the window but how am I supposed to access the

Currently I´m trying to add the constraint in the
method in a subclassed
. Wrong approach maybe?

Thanks in advance

Answer Source

Edit: this solution is no longer acceptable since OS X El Capitan which has a different views hierarchy in a window frame. Look for the sam's answer where he suggests to use a new NSLayoutConstraint methods and properties (constraints activation) that were introduced in Yosemite.

I've faced the same issue yesterday

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download