"Unable to simultaneously satisfy constraints" error with UIScrollView - iphone

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

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)

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.

Why is this autolayout specification not sufficient?

I am trying to get rid of those annoying warnings in Interface Builder, but I do not understand what it is complaining about (all Interface Builder, no code):
I have specified a fixed with, fixed height and fixed distances to right and top.
Yet the warning tells me
Needs Constraints for: Y position, height
Needs Constraints for: X position, width
Can someone please explain how these are constraints are not sufficient?
Edit
Also, when using the "automatic" add constraints commands, it does nothing and the errors remain.
I would suspect the superview is not pinned to a size in interface builder. Autolayout constraints seem to solve everything simultaneously and an error message that looks like it relates to one view can just as easily relate to the other view in the relationship.
What is - (NSArray *)constraintsAffectingLayoutForAxis:(UILayoutConstraintAxis)axis telling you?

Same Auto Layout constraints behaving differently in portrait and landscape

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.