Same Auto Layout constraints behaving differently in portrait and landscape - iphone

I was digging into iOS 6.0 new feature Auto Layout, I created a sample app which has one view controller and two UIView as subview.I provided following constraints:
When I execute the following app in Landscape mode and rotate it to portrait, it works fine but when I execute it in portrait mode and rotate to Landscape it throws exception:
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:0x748cae0 h=--- v=--- H:[UIWindow:0x716a060(768)]>",
"<NSLayoutConstraint:0x716d980 V:[UIView:0x716d540]-(736)-| (Names: '|':UIView:0x716d0c0 )>",
"<NSLayoutConstraint:0x716d8c0 V:|-(20)-[UIView:0x716d540] (Names: '|':UIView:0x716d0c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7176020 h=-&- v=-&- UIView:0x716d0c0.width == UIWindow:0x716a060.width - 20>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x716d980 V:[UIView:0x716d540]-(736)-| (Names: '|':UIView:0x716d0c0 )>
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.
2012-10-22 11:37:37.297 AutoLayoutSample[679: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:0x748cae0 h=--- v=--- H:[UIWindow:0x716a060(768)]>",
"<NSLayoutConstraint:0x716d880 V:[UIView:0x716d230]-(730)-| (Names: '|':UIView:0x716d0c0 )>",
"<NSLayoutConstraint:0x716d840 V:|-(20)-[UIView:0x716d230] (Names: '|':UIView:0x716d0c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7176020 h=-&- v=-&- UIView:0x716d0c0.width == UIWindow:0x716a060.width - 20>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x716d880 V:[UIView:0x716d230]-(730)-| (Names: '|':UIView:0x716d0c0 )>
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.
My question is why it is throwing exception when I execute in portrait mode and rotate to landscape?And why constrains are behaving differently?

The system is automatically turning the default resizing masks into constraints, which then conflict with yours. Add calls to [view setTranslatesAutoresizingMaskIntoConstraints:NO] for both of your subviews and the NSAutoresizingMaskLayoutConstraints will go away, along with the exception.

Related

Swift : how to check which view is causing constraints error

I am getting the following error when trying to load a VC:
Thread 1: Exception: "Unable to activate constraint with anchors
<NSLayoutXAxisAnchor:0x280fea300 \"i6.I6FuelSheetTextField:0x1030fe400.centerX\"> and
<NSLayoutXAxisAnchor:0x280fea440
\"UILayoutGuide:0x282327800'UIViewSafeAreaLayoutGuide'.centerX\"> because they have no common
ancestor. Does the constraint or its anchors reference items in different view hierarchies?
That's illegal."
How can I identify which views these addresses are referring to?
This is occurring because you are trying to constraint two views that are unrelated to each other. You are lucky enough to get enough information from the error. You are using a component that an instance of I6FuelSheetTextField and you trying to constraint it's centerX attribute. So, I think the error itself is pretty explanatory.
Note: It could also be the case when you forget to add a view to another view's subview.

UIView-Encapsulated-Layout-Width and LayoutConstraint

I get the following errors when I run the application. What kind of visual problem do I have ?
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-06-15 17:45:15.916490+0300 ...[3888:779219] [LayoutConstraints] 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.
(
"<SnapKit.LayoutConstraint:0x280cf51a0#MainTableViewController.swift#3209 ....DeviceTableViewCell:0x10c82cc00.width == 375.0>",
"<NSLayoutConstraint:0x280be41e0 'UIView-Encapsulated-Layout-Width' ....DeviceTableViewCell:0x10c82cc00'cellId'.width == 0 (active)>"
)
Will attempt to recover by breaking constraint
<SnapKit.LayoutConstraint:0x280cf51a0#MainTableViewController.swift#3209 ...DeviceTableViewCell:0x10c82cc00.width == 375.0>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
cell.snp.makeConstraints { (make) in
make.top.equalTo(100)
make.height.equalTo(205)
make.width.equalTo(view.frame.width)
}
I think that you have 2 width constrains for the specific cell, so check that out.
go to your storyboard.
open the right side menu.
On the top click the size inspector and check your constrains.
Or try to change the priority of your width constrain.
make.width.equalTo(view.frame.width).priority(999)

XCode 7 Compilation Error with Swift

Can someone help me fix this issue? I added another ViewController and modally linked it to the original view controller. It originally worked, but I ran it again because I made change in text and now it will not compile. I deleted all constraints and deleted the "button" that it says is not correctly linked.
2015-10-26 00:48:43.611 XXXX[5790:2031206] 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:0x15ce8dac0 V:|-(20)-[UIInputSetContainerView:0x15ce2e050] (Names: '|':UITextEffectsWindow:0x15ce694a0 )>",
"<NSLayoutConstraint:0x15ce8e630 'UIInputWindowController-top' V:|-(0)-[UIInputSetContainerView:0x15ce2e050] (Names: '|':UITextEffectsWindow:0x15ce694a0 )>")
Will attempt to recover by breaking constraint
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.
2015-10-26 00:48:44.446 XXXXX[5790:2031206] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<XXXXXX.CreateAnAccountViewController 0x15cd1fd40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key SignUpLabel.'
*** First throw call stack:
(0x185198f5c 0x19a67ff80 0x185198c1c 0x18600f534 0x18aa4f9b8 0x18ab9b4b8 0x1850c2acc 0x18ab99ea0 0x18aa52cfc 0x18a827ea8 0x18a6ef258 0x18a6ef1b0 0x18af713a4 0x18aa3705c 0x18aa5c508 0x18aa5f294 0x18a7e60c0 0x18adea5d8 0x18adddcf8 0x18adddafc 0x18addddc4 0x18a7263e4 0x18a726360 0x18a70ec88 0x18a725c78 0x18a7258a8 0x18a71eadc 0x18a6efa2c 0x18a6edf18 0x1851505a4 0x185150038 0x18514dd38 0x18507cdc0 0x190518088 0x18a756f60 0x1000d56e4 0x19ae9e8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
You probably have an outlet in your view that is connected to a label (SignUpLabel) in your class that is not found.
Either your File's owner is not set to be your ViewController or you have deleted/renamed the label in your class and need to reset the outlet in your view.
You also have an error with your constraints but that shouldn't contribute to the crash.

Confused by conflicting autolayout constraints

I got this crashlog when I click on tabbar tabitem to change viewcontroller:
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:0xdb98e30 h=--- v=--- H:[UIWindow:0xc65c530(320)]>",
"<NSAutoresizingMaskLayoutConstraint:0xdbba9a0 h=-&- v=-&- UITransitionView:0xdb43ab0.width == UILayoutContainerView:0xdb42ef0.width>",
"<NSAutoresizingMaskLayoutConstraint:0xc680b80 h=-&- v=-&- UILayoutContainerView:0xdb42ef0.width == UIWindow:0xc65c530.width>",
"<NSAutoresizingMaskLayoutConstraint:0x119352f0 h=-&- v=-&- UIViewControllerWrapperView:0xc68a2c0.width == UITransitionView:0xdb43ab0.width>"
)
Will attempt to recover by breaking constraint
<NSAutoresizingMaskLayoutConstraint:0x119352f0 h=-&- v=-&- UIViewControllerWrapperView:0xc68a2c0.width == UITransitionView:0xdb43ab0.width>
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.
First, how are you applying these constraints? The most common cause of these conflict messages is adding constraints without ensuring they are the only ones the view has. Have you set the property
translatesAutoresizingMaskIntoConstraints = NO
before trying to set more? Because you are getting this exception at runtime it looks like Xcode has accepted what you are trying to do so you are probably adding constraints in code.
Did you add all of those constraints in the list that are given as conflicting? If so, remove them and replace them one by one to find which one you got wrong.
If you are doing all this in Xcode in what we used to know of as Interface Builder, use the new tools to examine all of the constraints and verify that you have not added constraints that conflict. Xcode can help you here.
If you are adding constraints in code but you have created the view in IB then you probably want to either manage all constraints in IB or you want to set the xib to NOT use autolayout, so that it does not apply constraints that conflict with what you later add.

"Unable to simultaneously satisfy constraints" error with UIScrollView

Created a simple ViewController, and added UIScrollView with a xib. When I'm trying to change the height of the scroll view, I'm getting a weird exception:
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) (
"",
"",
"",
"" )
Will attempt to recover by breaking constraint
(Names: '|':UIView:0xa4ab830 )>
Break on objc_exception_throw to catch this in the debugger. The
methods in the UIConstraintBasedLayoutDebugging category on UIView
listed in may also be helpful.
Here's how my xib looks:
Found on the SO that setting content size and setting translatesAutoresizingMaskIntoConstraints property to YES might help. Tried it, didn't work:
topScrollView.translatesAutoresizingMaskIntoConstraints = YES;
topScrollView.contentSize = CGSizeMake(1000, 2000);
EDIT: added screenshot