I recently updated Xcode and I got the following warnings:
I tried Editor -> Resolve Auto-Layout Issues -> Clear all constraints in view controller but it did not work... I am using Xcode 5. How do I remove the warnings?
In Xcode 5 the position of views on the canvas does not update when constraints are applied. Thus, it is possible to have constraints that specify a different position for the view than you see it in Interface Builder. You can correct this by pressing Command + Option + = or selecting "Update Frames" in the |-•-| menu (I think it looks like a tie fighter).
Update for Xcode 8:
The "Update Frames" command now has its own button. It's located just to the left of the Stack View / Alignment / Constraints buttons and looks like a reload arrow surrounded by corner brackets:
Select this view in Storyboard, then 'Editor -> Resolve Auto-Layout Issues -> Update All Constraints in View'
It works for me.
Xcode 8: I got this warning with 1 UICollectionView in the Storyboard and no constraints at all. Switching the "View as"-Device at the bottom to any other device and back removes the warning.
In XCode 6 the Warning is now accompanied with dimensions indicating where the view will be placed given the current constraints. If your constraints are correct (or you believe them to be) and the view (eg. a label) is not at that location, try changing the view's dimensions to the expected dimensions in the warning. If the view ends up in the right place and the warning goes away, it confirms that your constraints are working as expected.
Simply removing the constraints may remove the warning but won't necessarily give you the Auto Layout behavior you are hoping for.
In Xcode 8.1 there is now a refresh button to the far left, click your views and click that to be the equivalent of the old update frames.
To be more specific, Select your view, Go to Editor Menu -> from Resolve Auto Layout Issues select 'Clear Constraints'. This should clear your constraints and no longer give you warning when you move your components.
Related
In order to implement scroll view I do:
Create Cocoa Application
Go to XIB
Drag scroll view to the view window and set its constraints to 0
Everything seems fine until now
Under Bordered Scroll View (in the Document Outline) I press on Clip View and then View and resize that to any large number (under size inspector)
I add a button (for the sake of it) to the view (under clip view) (in the Document Outline) and sets its constraints
After this I immediately get the "Ambigious Layout. Position is ambigious for "View".
What am I doing wrong? Is this the proper way to add scrollview? It also seems rather difficult to add items to the scrollable area as I dont see the entire scrollable area in the xib.
Please help a noob.
In general this is a correct way to add a scroll view. (You can also create a view or set of sibling views, select them, and choose Editor > Embed In > Scroll View.)
If a view has no constraints, then Xcode will add sufficient constraints at build time. These constraints are not necessarily the ones that cause the view to behave like you want as things change size, but they're good enough to maintain the current layout of the canvas when things have their current sizes.
However, once you add constraints, Xcode will start insisting that the constraints are mutually-compatible (no conflicts) and sufficient to be unambiguous.
So, that explains why you get that warning. You have added some constraints, but not enough to make the layout unambiguous. You need to add enough. Xcode should explain in more detail what's needed, although there will necessarily be multiple possibilities for how to resolve the ambiguity.
In your case, I'm guessing that the size of the view in the scroll view is ambiguous. For example, you may have added constraints to position the button relative to the top and leading edge, and the button likely has intrinsic size, but you haven't constrained the view's bottom or trailing edges to the button. So, the size of the view could be anything.
Of course, rather than constraining the view's bottom and trailing edge to the button, you could just add explicit height and width constraints to it. Or whatever.
You may also need to constrain the view to the clip view.
You can also use Editor > Resolve Auto Layout Issues > Add Missing Constraints and see what Xcode adds. You can then change things from there if what Xcode added is not what you want.
For my Mac OS X app, I selected the controls on xib to embed in scroll view ( Editor > Embed In > Scroll View ) and applying the following constraints to Custom View (inside Scroll View -> Clip View) did work.
Where hight is to accommodate controls.
My application has a log window that displays lines in an NSTableView:
When I add auto layout constraints to the window no matter what I do I get a Misplaced View warning for the Clip View:
I've tried updating its frame, updating its constraints, and resetting to suggested constraints, but nothing gets rid of the warning. The window displays and resizes correctly at runtime, and it doesn't even appear to be possible to add constraints to the Clip View itself.
I've pushed the code to github if you want to look at it in Xcode: https://github.com/MagerValp/AutoDMG/tree/e57b0140e3fc3f7f9e0d4550341ed249a6cf5378. The code requires the 10.10 SDK to compile, but the xib should be viewable in Xcode 5 and up.
I met the same issue recently, warning about Clip view expected value is 17px larger than actual value.
I believe it is a bug of Xcode. And I do find a workaround to fix it(other than downgrading my OS to 10.9).
The solution is to edit the attributes of tableView in IB, disable "Headers". Don't show table headers and the warning will be magically gone. And we can guess that by default the table header is 17px :)
It's just a workaround, not an ideal solution. This is not our fault. The best solution is to wait for Apple to fix this Xcode bug.
Scrollviews' subview hierarchy are only sort of compatible with auto layout.
One way around this is to constrain the clip view so it is not bothering you.
Then in the inspector, mark those constraints to be removed at runtime.
ScrollCiew
ClipCiew
TableView
If the error is coming from ClipView.
Check the ScrollView size, remember it.
And then click ScrollView as target, open up size inspector, enable Intrinsic Size using Placeholder with ScrollView size.
I use the Xcode 12.3, the latest version of Xcode. But also have the same warning. I remove the misplaced view warning by change the TableView Content Mode from View Based to Cell Based and then the warning disappeared. And then I change back to View Based. The warning will never appeared again.
I have two buttons that I want to be kept the same size, but the problem is that they have two different parent views. Autolayout seems to be ignoring the "equal size" constraint in this scenario. Constraining buttons with the same parent view works just fine.
I've created a very simple example that depicts what I am seeing:
As you can see from the above, buttons Two and Three are both set to have the same size constraint as button One. The only difference is that button Three is contained within another NSView. There are no width constraints that are linking button Three and its containing view.
However, when I run and resize the window, it looks like:
It doesn't matter whether I use the Interface Builder layout, or do it in code using the -[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:] method.
What am I missing? Is this not supported by Autolayout? Thanks a lot.
Edited: Added screenshot to indicate button Three's constraints.
This should work OK. I set up an example project to do the same thing. I have three buttons with equal width constraints between button one and button two. Then the same between button two and button three. Button one has a trailing edge constraint relative to it's parent view.
Note that between the second and third button, Interface Builder didn't let me do this in the main window. Instead, I had to do it using the document list on the left.
The result can be seen below:
Here's the link to the project:
https://github.com/MaxMacleod/ThreeButtonConstraintTest1
Couple of caveats. First, this is an iOS rather than an OS X project (I'm an iOS guy!). However the principles should be the same. Secondly, this doesn't pinpoint the exact reason why your project isn't working. However, if you can compare what this sample project does against yours, we can figure it out. I'll then update this answer. Better still if you could make your project available, I'd be happy to take a look.
I was creating a simple GUI for an app, and came across this seemingly unusual behaviour when running.
Here is what my xib file looks like:
And here is what happens when I run the app:
I have tried creating a new view and using that instead, but it displays the same behaviour.
Why is the window getting resized? And more importantly, how can you prevent it from happening?
Thanks!
I've had this problem lately with Xcode's auto-layout feature. I solved it by manually deleting all the constraints and using the "Editor->Resolve Auto-Layout Issues->Reset to Suggested Constraints in Window.
You either need to use Auto Layout Constraints or Springs and Struts (old style ) to configure your views. The window normally will adjust itself as needed with auto layout.
With old style you have to manage the window frame or at least its content view frame.
Go to .xib file
and select size inspector. and from that set autosizing according to your rquirement.
Feel free to contact.
Increase main window width and hight.
I drag a tab view into my custom view, and set its frame. Xcode automatically generate several NSLayoutConstraint objects those will decide its frame during auto-layout.
As shown above, a constraint which indicates the distance between right edge of the tab view and the RIGHT edge of its super view.
However, I do not want a constraint like this. What I want is a constraint which indecates the distance between the right edge of the tab view and the LEFT edge of its suber view. OR, the width of the tab view itself.
How should I do?
BTW, I tried delete the constraint, but Xcode generated this constraint back immediately. Therefore I could not add one (and actually I do not know how to add one, either).
There is a minimum number of constraints required on each axis of the view, hence you should add a new constraint first before deleting existing one to make sure Xcode understands how to layout the views properly.
Try to add a new constraint by clicking a view and then click on the middle button at the bottom right options in your screenshot:
go through following link, which explain auto layout..
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2