In Session 204 of the 2017 WWDC it was mentioned that you can now use Auto Layout in the UIViewController navigationItem.titleView.
I tried various different options including the mentioned intrinsicContentSIze, custom view with custom frame as well as a complete Auto Layout approach with fixed height.
No matter what I do, the navigation bar always shrinks down my views to 44 points.
Furthermore when using the AutoLayout only approach, I'm getting this constraint error:
14:03:41.049847+0800 dfgd[60535:11623968] [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.
(
"<NSLayoutConstraint:0x600000092a70 UILayoutGuide:0x6000001b3160'TitleView(0x7f8beb6061c0)'.height == 44 (active)>",
"<NSLayoutConstraint:0x600000092250 UIView:0x7f8beb602f50.height == 200 (active)>",
"<NSLayoutConstraint:0x6000000920c0 V:[UIView:0x7f8beb602f50]-(10)-| (active, names: '|':dfgd.CustomView:0x7f8beb602930 )>",
"<NSLayoutConstraint:0x6000000925c0 UIView:0x7f8beb602f50.centerY == dfgd.CustomView:0x7f8beb602930.centerY (active)>",
"<NSLayoutConstraint:0x6040000938d0 dfgd.CustomView:0x7f8beb602930.top >= UILayoutGuide:0x6000001b3160'TitleView(0x7f8beb6061c0)'.top (active)>",
"<NSLayoutConstraint:0x604000094a50 dfgd.CustomView:0x7f8beb602930.bottom <= UILayoutGuide:0x6000001b3160'TitleView(0x7f8beb6061c0)'.bottom (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000092250 UIView:0x7f8beb602f50.height == 200 (active)>
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.
QUESTION:
Has anybody managed to make that work? How do you get custom navigation bar heights to adopt to your title views?
Related
Just making my first steps in IOS development, and I want to bring my Android app to IOS.
The issue it with UICollectionView. I need the cells to be of fixed constant width, and the image inside the cell - of fixed height. So, I've set the width constraint of StackView to 105 and height constraint for ImageView to 147.
Everything looks as expected, however I get warnings in the console:
2021-02-21 22:23:17.490472+0200 myapp-ios[20727:783655] [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.
(
"<NSLayoutConstraint:0x600002193890 UIStackView:0x7f90efc173d0.width == 105 (active)>",
"<NSLayoutConstraint:0x6000021938e0 H:[UIStackView:0x7f90efc173d0]-(0)-| (active, names: '|':UIView:0x7f90efc1d840 )>",
"<NSLayoutConstraint:0x600002193930 H:|-(0)-[UIStackView:0x7f90efc173d0] (active, names: '|':UIView:0x7f90efc1d840 )>",
"<NSLayoutConstraint:0x600002193a20 'UIIBSystemGenerated' myapp_ios.ShowCell:0x7f90efc23ec0.leading == UIView:0x7f90efc1d840.leading (active)>",
"<NSLayoutConstraint:0x600002193a70 'UIIBSystemGenerated' H:[UIView:0x7f90efc1d840]-(0)-| (active, names: '|':myapp_ios.ShowCell:0x7f90efc23ec0 )>",
"<NSLayoutConstraint:0x6000021967b0 'UIView-Encapsulated-Layout-Width' myapp_ios.ShowCell:0x7f90efc23ec0.width == 50 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600002193890 UIStackView:0x7f90efc173d0.width == 105 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
I also tried to set width and height constraints of ImageView only to 105x147, it looks the same, and the warning is pretty much the same. Basically if no width or height constraints set - there is no warning, once I add any of them - it appears.
Here are the constraints:
I would appreciate you helping me understand the potential problem.
I think removing the width constraint of the stack view will work.
I'm just learning Swift with the Start Developing iOS Apps (Swift) Tutorial. I'm creating this custom Rating Control but every time i run the App is sends following Error:
2017-08-09 15:49:41.894597+0200 FoodTracker[5051:2273797] [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.
(
"<NSLayoutConstraint:0x17409af90 UIButton:0x100c12d90.width == 44 (active)>",
"<NSLayoutConstraint:0x17009c160 'UISV-canvas-connection' FoodTracker.RatingControl:0x100c02400.leading == UIButton:0x100c12d90.leading (active)>",
"<NSLayoutConstraint:0x17009c200 'UISV-canvas-connection' H:[UIButton:0x100c12d90]-(0)-| (active, names: '|':FoodTracker.RatingControl:0x100c02400 )>",
"<NSLayoutConstraint:0x17009bee0 'UIView-Encapsulated-Layout-Width' FoodTracker.RatingControl:0x100c02400.width == 343 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17409af90 UIButton:0x100c12d90.width == 44 (active)>
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.
2017-08-09 15:49:41.895770+0200 FoodTracker[5051:2273797] [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.
(
"<NSLayoutConstraint:0x17409af40 UIButton:0x100c12d90.height == 44 (active)>",
"<NSLayoutConstraint:0x17009c250 'UISV-canvas-connection' FoodTracker.RatingControl:0x100c02400.top == UIButton:0x100c12d90.top (active)>",
"<NSLayoutConstraint:0x17009c340 'UISV-canvas-connection' V:[UIButton:0x100c12d90]-(0)-| (active, names: '|':FoodTracker.RatingControl:0x100c02400 )>",
"<NSLayoutConstraint:0x17009bf30 'UIView-Encapsulated-Layout-Height' FoodTracker.RatingControl:0x100c02400.height == 50 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17409af40 UIButton:0x100c12d90.height == 44 (active)>
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.
I set the constraints for Button width == 44 and for Button height == 44, but none of the other constraints. I did everything as described in the Tutorial and have no clue why it doesn't work. I Checked all Constraints i can find but i'm not sure if it were all as I'm not very experienced with Xcode. Do anyone have a clue how to solve the Problem?
This is how it should look like: But this is how it looks: (Only The Red Area is important)
I also faced similar issue. The solution is simple, as shown, move (drag and drop) horizontal stack view under the vertical stack view as shown.
Based on the error message, I think you have embedded the button inside a UIStackView. The stack view has incorrect constraints, or no constraints at all and is using the autoresizing mask. The stack view is being given a size of 343x50 and is forcing the button to match.
Looks like you have a UIStackView. Remove the UIButton out of the UIStackView and set that UIButton's top constraint the same spacing you defined in your UIStackView and set the UIButton's align leading edge to the UiStackView and you're good
I have found reason and solution.
Horizontal Stack View - filling whole own internal space by vertical and horizontal. It's mean - Horizontal Stack View will set height and wight for internal items to Fill all available space.
Only way to remove such warning which i found - is set width/height of Horizontal Stack View to fit perfectly with/height of all internal elements: 252x44
I will use the following notation to explain the invovled views:
{V} – the ‘superview’, i.e. the main view of the root controller
{Q} – a rectangle at the center of the screen used as a quiz
{W} – a white bar above {Q}
I’m getting the following output when running on iPad-Air2 simulator:
2016-11-03 08:09:07.700117 MyApp[16645:6976134] [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.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x60000009d600 h=--& v=--& QuizButtons:0x7fcb8e521830.width == 717 (active)>",
"<NSLayoutConstraint:0x608000281fe0 H:|-(0)-[ImgWhiteBar:0x7fcb8e525020] (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>",
"<NSLayoutConstraint:0x608000282210 ImgWhiteBar:0x7fcb8e525020.width == 1.07143*QuizButtons:0x7fcb8e521830.width (active)>",
"<NSLayoutConstraint:0x60000009b9e0 'UIView-Encapsulated-Layout-Width' ViewTestVC:0x7fcb8e639b30.width == 768 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6080002820d0 H:[ImgWhiteBar:0x7fcb8e525020]-(0)-| (active, names: '|':ViewTestVC:0x7fcb8e639b30 )>
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.
My interpretation to logged constraints is this:
{Q}: default <h=--& v=--&>, width =717
Horiz: {V.lead} -0- {W}
Horiz: {W} -0- {V.trail}
{W.width} = 1.07 * {Q.width}
{V.width} = 768
Or maybe a bit simpler
{Q.width} must be 717
{W.width} must be 768.21531
{W} must touch both sides of {V}
{V.width} = 768
Questions:
Is my interpretation correct?
What is the problem here? It is due to the inaccuracy of the 768.2 vs 768? If yes, who told Xcode to use 717? I told {Q.width} to be {W.width}/[14:15]
Will appreciate any help here!
EDIT
Here are three of the constraints:
The list of the conflicting constraints includes h=--& v=--& which is the default non-autolayout form.
I was trying to get the initial size and position using auto-layout, and then tried to turn auto-layout off by setting translatesAutoresizingMaskIntoConstraints=YES. I got an answer in the Apple developer forum saying that in such case I need to remove all constraints for the view, possibly by removing from the superview and adding back.
TIP
While investigating this bug, I have found a way to make the constraints-conflict log much easier to understand. The problem is that the views appear anonymous, specifying only the class but not the name.
To make your views identifiable, open one of your .m files and add a new class for each view you want to identify, like this:
#interface ImgWhiteBar: UIImageView
#end
#implementation ImgWhiteBar
#end
#interface Spacer1: UIView
#end
#implementation Spacer1
#end
After that, in InterfaceBuilder, select each view, and then at the "Identity Inspector" on the right modify the generic class (UIVIew, UIImageView etc.) into one of the classes you just created.
Now run again, and Abracadabra - all views are now identified with their custom classes, allowing you to understand what is going on there.
Have fun debugging constraints!
I'm trying something really simple and I do not understand the constraint conflict resulting. Let me explain:
I have a nice view controller with a full screen vertical UIStackView (contraints set to 0 to top, leading, trailing and bottom) with two views inside.
The top view as a constrained height of 200pt, the bottom view has no constraint. As the stack view has a Fill distribution mode, everything is fine.
Now, I want the stack view to switch to horizontal axis on landscape on iPhones. So, on my storyboard I select the wAny|hCompact size class, uninstall the height constraint, add a width constraint, and select horizontal axis...
The behavior works alright, unfortunately, it detects a constraint conflict I can't explain :
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.
(
"<NSLayoutConstraint:0x7fba62c1b7f0 H:[UIStackView:0x7fba62c0a3c0]-(0)-| (Names: '|':UIView:0x7fba62c0bd10 )>",
"<NSLayoutConstraint:0x7fba62c1b890 H:|-(0)-[UIStackView:0x7fba62c0a3c0] (Names: '|':UIView:0x7fba62c0bd10 )>",
"<NSLayoutConstraint:0x7fba62c1ba80 H:[UIView:0x7fba62c15420(200)]>",
"<NSLayoutConstraint:0x7fba62d1c230 'UISV-canvas-connection' UIStackView:0x7fba62c0a3c0.leading == UIView:0x7fba62c15420.leading>",
"<NSLayoutConstraint:0x7fba62dcad80 'UISV-canvas-connection' H:[UIView:0x7fba62c15420]-(0)-| (Names: '|':UIStackView:0x7fba62c0a3c0 )>",
"<NSLayoutConstraint:0x7fba62dc69d0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fba62c0bd10(736)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fba62c1ba80 H:[UIView:0x7fba62c15420(200)]>
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.
So if someone can tell me what is wrong!
Ran into this problem and it appears to possibly be a bug in UIStackView where an internally generated constraint from the previous/default size class is lingering. This workaround (Swift) works for me:
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
self.setNeedsLayout()
self.layoutIfNeeded()
}
I am trying to implement a feed of news (somehow like instagram without comments or likes). It works, but xcode keep showing this error. I tried change all the constraints, however, I cant get to work. The tableview has a height of 475 and the image has the height of 400, leaving 75 for the white area with labels.
I did use
self.tableView.estimatedRowHeight = 475;
self.tableView.rowHeight = UITableViewAutomaticDimension;
Any help?
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:0x174096530 UIImageView:0x1743e9000.top == UITableViewCellContentView:0x17418af80.topMargin + 13>",
"<NSLayoutConstraint:0x1740977f0 V:[PFImageView:0x1743e8e00]-(0)-| (Names: '|':UITableViewCellContentView:0x17418af80 )>",
"<NSLayoutConstraint:0x174097840 V:[UIImageView:0x1743e9000]-(24)-[PFImageView:0x1743e8e00]>",
"<NSLayoutConstraint:0x174097890 H:|-(0)-[PFImageView:0x1743e8e00] (Names: '|':UITableViewCellContentView:0x17418af80 )>",
"<NSLayoutConstraint:0x174097930 H:[PFImageView:0x1743e8e00]-(0)-| (Names: '|':UITableViewCellContentView:0x17418af80 )>",
"<NSLayoutConstraint:0x174097ac0 PFImageView:0x1743e8e00.width == PFImageView:0x1743e8e00.height>",
"<NSLayoutConstraint:0x174097b60 V:[UIImageView:0x1743e9000(30)]>",
"<NSLayoutConstraint:0x174092ed0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x17418af80(375)]>",
"<NSLayoutConstraint:0x174092f20 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x17418af80(44)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174097b60 V:[UIImageView:0x1743e9000(30)]>
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.
I actually solved the problem changing the priority from the bottom of the image constrain to 750. Thanks for the help.