Why does my storyboard keep resizing my views - ios

I have a UIStoryBoard with a ViewController that contains a UITableView. I added Views above and below the UITableView to act as a header/footer that will scroll with the UITableView, that is all working appropriately. The problem is when I resize the header/footer Views, they show up correctly in the preview, but they are not the correct size in the app.
Here is how it looks in StoryBoard:
And when I run it on the app the top View takes up the entire screen. But here is the weird thing, if I close Xcode and reopen it both the header and footer views have a height of 568, which I'm assuming is why they look so huge in the app. Why is Xcode resizing these views? I have tried removing all constraints but it doesn't make any difference.
I actually removed the ViewController entirely from the storyboard and remade it and it is still doing this same behavior.
Here is what it looks like after I restart Xcode:
EDIT
Getting this output in the console:
2015-05-06 14:16:43.214 FitHub[16063:674572] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fe46b2ac6a0 V:[UILabel:0x7fe46b2ac6f0'Settings']-(16)-| (Names: '|':UIView:0x7fe46b13a7a0 )>",
"<NSLayoutConstraint:0x7fe46b2ad6b0 V:[UIImageView:0x7fe46b2ad700]-(13)-[UILabel:0x7fe46b2ac6f0'Settings']>",
"<NSLayoutConstraint:0x7fe46b2b2360 V:|-(16)-[UIImageView:0x7fe46b2ad700] (Names: '|':UIView:0x7fe46b13a7a0 )>",
"<NSLayoutConstraint:0x7fe46b2b22e0 V:[UIImageView:0x7fe46b2ad700(35)]>",
"<NSLayoutConstraint:0x7fe46b2b2030 V:[UILabel:0x7fe46b2ac6f0'Settings'(30)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7fe46b2c9360 h=--& v=--& V:[UIView:0x7fe46b13a7a0(568)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fe46b2b22e0 V:[UIImageView:0x7fe46b2ad700(35)]>
Thanks in advance.

Ok, so I have been working in the size class of wCompact hRegular, because we are only developing for iPhones in portrait mode. I had to change the size class to wAny hAny and then resize the frame height from 568 to 110.
I am curious though, is there a reason why I had to do it for this specific controller and not for any other ones?

Related

UITableViewAutomaticDimension not working properly in iOS 9

In my app I have custom tableViewCells with a fixed ratio (16x9). To achieve that, I placed a view in the cell, fixed it to its parent view (although I did it in interface builder: V/H:|-[innerView]-|).
Also, I put a ratio constraint on it.
In my tableViewController I'm using UITableViewAutomaticDimension as a table cell height.
The estimated row height is 180, wich is the exact size the cell will have on a 320px wide display (as I, as you can see, do).
I'm still deploying for 8.4, but when running the project on an Device with iOS 9, I'm getting tons of auto layout warnings, although everything works fine and looks perfect.
The warning itself is absolutely right. There are two constraints I don't want – these that iOS added on its own.
2015-09-29 11:24:57.771 app[1039:324736] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x147d3e0d0 UIView:0x14901ff70.height == 0.5625*UIView:0x14901ff70.width>",
"<NSLayoutConstraint:0x147dd0210 H:|-(0)-[UIView:0x14901ff70] (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x147deeca0 V:|-(0)-[UIView:0x14901ff70] (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x149053c30 V:[UIView:0x14901ff70]-(0)-| (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x147dbc2b0 H:[UIView:0x14901ff70]-(0)-| (Names: '|':UITableViewCellContentView:0x14901f960 )>",
"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>",
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x147d3e0d0 UIView:0x14901ff70.height == 0.5625*UIView:0x14901ff70.width>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
The only thing I see here are the missing 0.5 pixels that iOS subtracted somehow magically.
The issue is the two constraints that the tableview adds automatically. UIView-Encapsulated-Layout-Height and width are probably the height and width the table view calculated for the cell during the initial load, based on the cell's constraints at that time.
"<NSLayoutConstraint:0x149070800 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x14901f960(179.5)]>",
"<NSLayoutConstraint:0x1490707b0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x14901f960(320)]>"
As the priorities for these constraints are 1000 what you can do is lower your height and width constraint priorities and let the encapsulated size to be applied when needed (at load).
Seems you have added two ratio constraints added on two different views.
One that should be there is,
<NSLayoutConstraint:0x14d939e00 UIView:0x14da107f0.width ==
1.77778*UIView:0x14da107f0.height>
has memory address 0x14d939e00 added on UIView with address 0x14da107f0.
The other one is breaking.
<NSLayoutConstraint:0x14c5eae90 UIView:0x14c5ead30.height ==
0.5625*UIView:0x14c5ead30.width>
This one is added on a UIView (0x14c5ead30). Look for this view and remove this ratio constraint.

Contraints greyed-out in Xcode

I am trying to debug+understand autolayout constraints and I notice that when debugging the view with xcode (using the cool layer thing) I noticed that on one element in the view the constraints look like this
and the view is indeed ignoring these constraints.
All constraints have the same priority (1000) since I want them all. All constraints were made with interface builder and not through code, and there are not warning or conflicts in IB.
But in runtime I do see this
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x79684f10 V:[UIImageView:0x79686800(>=160)]>",
"<NSLayoutConstraint:0x7968a310 V:[UIImageView:0x79686800]-(130.5)-| (Names: '|':UIView:0x79686790 )>",
"<NSLayoutConstraint:0x7968a340 V:|-(0)-[UIImageView:0x79686800] (Names: '|':UIView:0x79686790 )>",
"<NSLayoutConstraint:0x796997b0 'UIView-Encapsulated-Layout-Height' V:[CoverCell:0x79686570(192)]>",
"<NSAutoresizingMaskLayoutConstraint:0x7969cd30 h=-&- v=-&- UIView:0x79686790.height == CoverCell:0x79686570.height>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x79684f10 V:[UIImageView:0x79686800(>=160)]>
So from this I understand that some rules conflict, but I'm not sure how to read this
the >=160 is a rule on the UIImageView so it would have height of atleast 160 and 130.5 is the bottom padding of the imageview (so when using systemLayoutSizeFittingSize:UILayoutFittingCompressedSize the height won't be 0. So the minimum height for the entire cell is 160+130.5)
The rest of the error I don't understand.
What is wrong with the constraints and why do constraint conflicts occur in runtime and not in IB?
XCode 6 now supports different layouts. This greyed out constraints exist in Compact Width | Any Height layout, for example, but you currently editing Any Width | Any Height.
More detailed:
Storyboard View Elements Greyed Out
It depends. If you don't use size classes the grey ones are the removed ones. And you need to remove them second time. No matter how stupid it sounds.
If you use size classes, it means that your current size class is different than for greyed constraint. (however the first scenario is also possible...)
In your case it looks like this is the first case. You need to remove greyed constraints once again.

Constraints are not working as expected in landscape orientation

I test very simple layout with autolayout use storyboard only(no code any where)
i dropped the Button object wAny, hAny and then switch size class to wCompact, hAny
and add Constraint 'Center Horizontally in Container' & 'Top Space to Top layout guide'.
next i switch size class to wAny, hCompact and add constraint 'Center Vertically in Container' & 'Trailling space to Container Margin' and width,height constraint
that's all i added constraints, there is no warning and error in storyboard.
i expected as top centered button in portrait and right centered in landscape.
portrait is running normally but preview and simulator show me wrong result when i was change orientation with error log.
like this
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"\<_UILayoutSupportConstraint:0x7a065db0 V:[_UILayoutGuide:0x7a067440(0)]>",
"<_UILayoutSupportConstraint:0x7a068010 V:|-(0)-[_UILayoutGuide:0x7a067440] (Names: '|':UIView:0x7a0661d0 )>",
"<NSLayoutConstraint:0x7a0680b0 V:[_UILayoutGuide:0x7a067440]-(20)-[UIButton:0x7a066740'Button']>",
"<NSLayoutConstraint:0x7a06d9e0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7a0661d0(320)]>",
"<NSLayoutConstraint:0x7a068050 UIView:0x7a0661d0.centerY == UIButton:0x7a066740'Button'.centerY>",
"<NSLayoutConstraint:0x7a0680e0 V:[UIButton:0x7a066740'Button'(30)]>"
)
Will attempt to recover by breaking constraint "<NSLayoutConstraint:0x7a0680e0 V:[UIButton:0x7a066740'Button'(30)]>
and button fills width and height its container view.
i can't figure out what i did wrong?
am i missing something important about autolayout(with orientation)?
plz help me
(sorry for my bad english. i'm non english native speaker-)
Your problem is that wCompact|hAny is for iPhones in portrait or landscape. So you end up with conflicting constraints in landscape because all of your constraints apply. You should use wCompact|hRegular for iPhones in portrait.

Autolayout contraint error

So this autolayout error. Which I know why it is there but I am not sure how can I fix it. As with error its clear that its not able to resolve the constraints.
In portrait mode all 47 episode are listed and can be scrolled to. But in landscape mode it cant, which is clear as height of table is not changing thats way its is still down there but can't scroll to it.
So this is how I have setup.
Where as view controller has two view which works as placeholder upper is of for iAds and lower is holding table view. Idea was behind this. if ad is not loaded I will set height of View to zero which holds iADBanner. So that Table view takes up all space. (Got this idea from Ray Wenderlich's app level me up.) I was struggling with auto layout initially but I made it right so that view are taking up all width when sim goes to portrait mode. but somehow I am not able to fix the height of view which holds tableView.
Below are the screenshot of constraints.
I tried to be as descriptive as I can. but I am looking for more than just answer. I want to get to know this completely so that I will most likely won't have problem in future. I have finished raywenderlich tutorial already. So Any other pointer would be very much appreciate along with the answer.
2014-07-30 21:40:37.326 Test[85608:60b] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) (
"<NSLayoutConstraint:0xa5afbc0 UIView:0xa69b7d0.width == 0.682303*UIView:0xa69b830.height>",
"<NSLayoutConstraint:0xa5afc80 V:|-(50)-[UIView:0xa69b830] (Names: '|':UIView:0xa69b7d0 )>",
"<NSLayoutConstraint:0xa5afdc0 V:[UIView:0xa69b830]-(0)-[_UILayoutGuide:0xa5a8410]>",
"<_UILayoutSupportConstraint:0xa5a7d20 V:[_UILayoutGuide:0xa5a8410(0)]>",
"<_UILayoutSupportConstraint:0xa5af490 _UILayoutGuide:0xa5a8410.bottom == UIView:0xa69b7d0.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0xa792d10 h=--& v=--& H:[UIView:0xa69b7d0(480)]>",
"<NSAutoresizingMaskLayoutConstraint:0xa792dd0 h=--& v=--& V:[UIView:0xa69b7d0(271)]>" )
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xa5afdc0 V:[UIView:0xa69b830]-(0)-[_UILayoutGuide:0xa5a8410]>
Break on objc_exception_throw to catch this in the debugger. The
methods in the UIConstraintBasedLayoutDebugging category on UIView
listed in <UIKit/UIView.h> may also be helpful.
The list of constraints in the error log is the key to understanding this type of problem. What you want to do is look at it carefully to correlate which lines refer to which constraints in your code/ui builder, and which hexadecimal address refers to which view.
V:[UIView:0xa69b830]-(0)-[_UILayoutGuide:0xa5a8410] is a constraint setting the bottom of a UIView to a layout guide, so most likely that's the last constraint in your screenshot "Vertical Space - Bottom layout guide - TableVi..." (presumably that's TableViewHolder truncated). That means UIView:0xa69b830 is your TableViewHolder.
V:|-(50)-[UIView:0xa69b830] (Names: '|':UIView:0xa69b7d0 ) is the constraint tying the top of TableViewHolder 50px from its superview, which must be UIView:0xa69b7d0.
UIView:0xa69b7d0.width == 0.682303*UIView:0xa69b830.height looks like an aspect ratio constraint between the superview width and the TableViewHolder height.
h=--& v=--& H:[UIView:0xa69b7d0(480)] and h=--& v=--& V:[UIView:0xa69b7d0(271)] are constraints on the superview that's derived from its autoresizingMask, where the width=480px, height=271px, and their top/left/width/height are fixed (based on h=--& v=--&). This is sort of the standard setup for the root view of a view controller — it's dimensions are managed manually by the view controller to fill the screen.
So once you have all that, you can see what the problem is: the superview has fixed dimensions 480x271. Meanwhile, TableViewHolder's height is being dictated by multiple conflicting constraints:
#1 and #2 are trying to stretch it vertically to fill its superview with a 50px margin at the top, so height = 271-50 = 221px.
#3 is trying to set the height as a ratio of the superview's width: height = 480/0.6823 = 703.5px
221 != 730.5!
Something's gotta give, and the OS just happened to pick #1, so the bottom of TableViewHolder extends past the bottom of the layout guide, making it stick out past the edge of the screen and inaccessible.
Your fix will likely involve getting rid of that aspect ratio constraint, but there might be other issues that appear once you fix that. Good luck!

Unable to simultaneously satisfy constraints - No constraints in place

I have gone through and removed every single user constraint yet I am still getting the following error ONLY after I rotate the device. I have absolutely no clue why though. Does anyone have any ideas?
2013-01-14 21:30:31.363 myApp[35869:c07] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>",
"<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>",
"<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260] (Names: '|':UIView:0xa330270 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
Let's look at these one by one.
"<NSAutoresizingMaskLayoutConstraint:0x84543d0 h=--& v=--& V:[UIView:0xa330270(768)]>"
This is saying view 0xa330270 (A) must be 768 points high.
"<NSLayoutConstraint:0xa338350 V:[UIView:0xa331260]-(-1)-| (Names: '|':UIView:0xa330270 )>"
This is saying view 0xa331260 (B)'s bottom edge must be a gap of -1 from the bottom of A, which is it's superview.
"<NSLayoutConstraint:0xa338390 V:|-(841)-[UIView:0xa331260] (Names: '|':UIView:0xa330270 )>"
This is saying that B's top edge must be a gap of 841 points from the top of its superview, A.
These three things can't all be true - A can't be 768 points high, and contain a subview with a top edge 841 points inset from the top and -1 points inset from the bottom. Where have you defined each of these constraints?
You haven't said what layout you are trying to achieve, but it looks like you might have an autoresizing mask on the superview that is preventing it changing in height when you rotate the device. As far as I know the autoresizing constraints only appear if you have added views programmatically, since a storyboard or xib is either all-autolayout, or not. Unless you are doing something like adding an auto laid out view (loaded from a nib?) to another view from a non-autolayout nib?
Its worth knowing the basics, and understand what Apple/Xcode is trying to tell you through the logs
H = Horizontal constraint(for leading and Trailing)
V = Vertical constraint(top and bottom edge)
h = height
w = width
TopEdge -> V:|-(points)-[VIEW:memoryAddress]
BottomEdge -> V:[VIEW:memoryAddress]-(points)-|
Leading -> H:|-(points)-[VIEW:memoryAddress]
Trailing -> H:[VIEW:memoryAddress] -(points)-|
height -> h= --& v=--& V:[VIEW:memoryAddress((points)]
width -> VIEW:memoryAddress.width == points
between -> H:[VIEW 1]-(51)-[VIEW 2]
Once you understand this, reading your specific error is pretty easy
thanks to http://useYourLoaf.com for this complete solution:
http://useyourloaf.com/blog/using-identifiers-to-debug-autolayout.html
A quick tip I found buried in a WWDC 2015 session on Auto Layout that helps when debugging problems with constraints
If you have used Auto Layout you will be familiar with the log that Xcode spits out when you get something wrong. To create an example I modified my Stack View sample code and added a constraint to each of the images to give them a fixed width of 240 (not a good idea as we will see).
That works in regular width views such as the iPad but is too wide for a compact width view such as the iPhone in portrait. The console log at runtime is not fun to read. Skipping the boilerplate text you get a list of the problematic constraints:
"<NSLayoutConstraint:0x7fc1ab520360 H:[UIImageView:0x7fc1ab532650(240)]>",
"<NSLayoutConstraint:0x7fc1ab536ef0 H:[UIImageView:0x7fc1ab537380(240)]>",
"<NSLayoutConstraint:0x7fc1ab545cc0 UIView:0x7fc1ab53d870.trailingMargin == UIStackView:0x7fc1ab53dae0.trailing>",
"<NSLayoutConstraint:0x7fc1ab545d10 UIStackView:0x7fc1ab53dae0.leading == UIView:0x7fc1ab53d870.leadingMargin>",
"<NSLayoutConstraint:0x7fc1ab54e240 'UISV-alignment' UIStackView:0x7fc1ab53dc70.centerX == UIStackView:0x7fc1ab531a10.centerX>",
"<NSLayoutConstraint:0x7fc1ab5167c0 'UISV-canvas-connection' UIStackView:0x7fc1ab531a10.leading == UIImageView:0x7fc1ab532650.leading>",
"<NSLayoutConstraint:0x7fc1ab54ad80 'UISV-canvas-connection' H:[UIImageView:0x7fc1ab537380]-(0)-| (Names: '|':UIStackView:0x7fc1ab531a10 )>",
"<NSLayoutConstraint:0x7fc1ab5397d0 'UISV-canvas-connection' UIStackView:0x7fc1ab53dae0.leading == _UILayoutSpacer:0x7fc1ab54c3c0'UISV-alignment-spanner'.leading>",
"<NSLayoutConstraint:0x7fc1ab54a4a0 'UISV-canvas-connection' UIStackView:0x7fc1ab53dae0.centerX == UIStackView:0x7fc1ab53dc70.centerX>",
"<NSLayoutConstraint:0x7fc1ab54b110 'UISV-spacing' H:[UIImageView:0x7fc1ab532650]-(16)-[UIImageView:0x7fc1ab537380]>",
"<NSLayoutConstraint:0x7fc1ab548210 'UISV-spanning-boundary' _UILayoutSpacer:0x7fc1ab54c3c0'UISV-alignment-spanner'.leading <= UIStackView:0x7fc1ab531a10.leading>",
"<NSLayoutConstraint:0x7fc1ab551690 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fc1ab53d870(375)]>"
The log then tells you which of the above constraints it has decided to break:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fc1ab536ef0 H:[UIImageView:0x7fc1ab537380(240)]>
The log output uses the auto layout visual format language but it is hard to pick out my constraints from those created by the system. This is especially the case with stack views which are by design intended to create most of the constraints for you. In this trivial example I know the fixed width constraints that I just added broke things but it is hard to see that from the log and the more complex the view the harder it gets.
Adding an Identifier to a Constraint
The log gets a lot easier to understand if you add an identifier to each constraint (NSLayoutConstraint has had an identifier property since iOS 7). In Interface Builder find the constraint and add the identifier in the Attributes inspector (I am using $ as a prefix/suffix to make them stand out in the log):
Update 18-August-2015: As pointed out in the comments the identifier can only be edited in Interface Builder starting with Xcode 7. It is not visible in Xcode 6.4.
If adding the constraint in code:
constraint.identifier = "$HeartImageFixedWidth$"
It is trickier if you are using the visual format language which uses arrays of constraints. For example, consider the Swift code fragment to create a fixed width constraint for the heart image view:
let heartWidth = NSLayoutConstraint.constraintsWithVisualFormat("[heart(240)]",
options:[], metrics:nil, views:viewsDictionary)
Since heartWidth is an array of type [NSLayoutConstraint] setting the identifier is a little more work:
for constraint in heartWidth {
constraint.identifier = "$HeartImageFixedWidth$"
}
heartImage.addConstraints(heartWidth)
With identifies set for my constraints it is now much easier to find them in the log file (see the first four lines):
"<NSLayoutConstraint:0x7f92a305aeb0 '$ContainerStackViewLeading$' UIStackView:0x7f92a3053220.leading == UIView:0x7f92a3052fb0.leadingMargin + 32>",
"<NSLayoutConstraint:0x7f92a305b340 '$ContainerStackViewTrailing$' UIView:0x7f92a3052fb0.trailingMargin == UIStackView:0x7f92a3053220.trailing + 32>",
"<NSLayoutConstraint:0x7f92a301cf20 '$HeartImageFixedWidth$' H:[UIImageView:0x7f92a3047ef0(240)]>",
"<NSLayoutConstraint:0x7f92a3009be0 '$StarImageFixedWidth$' H:[UIImageView:0x7f92a304d190(240)]>",
"<NSLayoutConstraint:0x7f92a3060cc0 'UISV-alignment' UIStackView:0x7f92a30533b0.centerX == UIStackView:0x7f92a30472b0.centerX>",
"<NSLayoutConstraint:0x7f92a301c590 'UISV-canvas-connection' UIStackView:0x7f92a30472b0.leading == UIImageView:0x7f92a3047ef0.leading>",
"<NSLayoutConstraint:0x7f92a305f680 'UISV-canvas-connection' H:[UIImageView:0x7f92a304d190]-(0)-| (Names: '|':UIStackView:0x7f92a30472b0 )>",
"<NSLayoutConstraint:0x7f92a3064190 'UISV-canvas-connection' UIStackView:0x7f92a3053220.leading == _UILayoutSpacer:0x7f92a30608a0'UISV-alignment-spanner'.leading>",
"<NSLayoutConstraint:0x7f92a30415d0 'UISV-canvas-connection' UIStackView:0x7f92a3053220.centerX == UIStackView:0x7f92a30533b0.centerX>",
"<NSLayoutConstraint:0x7f92a305fa10 'UISV-spacing' H:[UIImageView:0x7f92a3047ef0]-(16)-[UIImageView:0x7f92a304d190]>",
"<NSLayoutConstraint:0x7f92a30508c0 'UISV-spanning-boundary' _UILayoutSpacer:0x7f92a30608a0'UISV-alignment-spanner'.leading <= UIStackView:0x7f92a30472b0.leading>",
"<NSLayoutConstraint:0x7f92a3063240 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7f92a3052fb0(375)]>"
It also much clearer which of the constraints the system has chosen to break:
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f92a3009be0 '$StarImageFixedWidth$' H:[UIImageView:0x7f92a304d190(240)]>
Adding identifiers to constraints is not without effort but it can pay off the next time you have to sort through the debug log of a complex layout.
Further Reading
WWDC 2015 Session 219 Mysteries of Auto Layout, Part 2
I guess this is not a common error, but I solved it somewhat in a layman way. I was getting cryptic messages like the one above. To make sense of it, I created dummy view classes and attached it to the views in my storyboard. For example, if I had a UIView, I created a class called AddressView and attached it to this view in story board. Its a bit time consuming, but it worked for me. After that instead of object-ids, I got class names which helped me zero in on the views that were causing the issue very easily. My error message now read,
2013-07-02 04:16:20.434 Myproject [2908:c07] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x9edeae0 V:|-(0)-[AddressView:0x143ee020] (Names: '|':MainView:0x129eb6a0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x11e998c0 h=--& v=--& V:[MainView:0x129eb6a0(704)]>",
"<NSLayoutConstraint:0x156720b0 V:[AddressView:0x143ee020]-(896)-| (Names: '|':MainView:0x129eb6a0 )>"
)
Here you can see, the names of my views MainView and Address view are causing the issue.
To resolve it, I just moved my subview (in this case Address view) and repositioned it back. I think the issue began as I was using a mix of new Automatic Layour in Xcode 4.5 and old skills or manually positioning the views.
Anyways, not sure if it was more luck than diligence, but nevertheless this could be a different way of debugging. Maybe this helps someone!
YourConstraintView.translatesAutoresizingMaskIntoConstraints = NO;
Did it for me.
I've fixed this problem be deleting all translatesAutoresizingMaskIntoConstraints properties from xib file (Open xib as a source code).
One note. You get this error in logs if you are testing using a personal hotspot connection, and the hotspot status bar is at the top. It throws off the constraints.
Hope this helps someone.. was driving me nuts.
For me this error was spitted when I gave tableView.estimatedRowHeight = UITableViewAutomaticDimension
This should have been tableView.estimatedRowHeight = "Some hardcoded value"
I had this problem and took me 2 days to figure out the source of the problem....
If you open a storyboard programmatically in you code just make sure you do it like this:
UIStoryboard *story = [UIStoryboard storyboardWithName:#"MovieMaker" bundle:nil];
UIViewController *vc = [story instantiateInitialViewController];
//this causes layout to break [self presentViewController:vc animated:YES completion:nil];
[self showViewController:vc sender:nil];
I was using the commented line (using presentViewController) and the orientation bug has happening throwing constraints conflicts that weren't my constraints... changing to showViewController all constraints conflicts were gone and orientation works...... (I don't really know why it works with show and not present... still thinking it's... ALIENS...)
This issue of the generated message "Unable to simultaneously satisfy contraints" in the debug console, is also experienced in XCode 9.4.
In my particular instance on the iPad simulator, the message would generate:
1) Only when placing the focus on a particular UITextField.
2) Even with all view contraints removed.
2) Even with all view contraints "Reset to Suggested Contraints".
However, when the software keyboard was toggled on to display, the message would not be generated.
Therefore, how much time should I spend on this issue, that in my instance is only generated when the software keyboard is toggled off.
this line solved my problem when logs like above in uitableviewCell
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension > CellHeight.rowHeight44 ? UITableView.automaticDimension : CellHeight.rowHeight44
}

Resources