I am using UITableViewController and I am loading customized UITableViewCell. All elements in the cell and the constraints are configured programmatically. The TableView looks like this
All works perfectly except when deleting a cell. I configured the tableView to fade cells when deleted. However, the cell gives a little jerk movement then it goes to the left instead of fading, and I get auto layout error messages in the Console: "Unable to simultaneously satisfy constraints" for below
"<NSLayoutConstraint:0x600002551a40 UIView:0x7fccbd5286f0.height == 100 (active)>",
"<NSLayoutConstraint:0x6000025505a0 V:|-(16)-[UIView:0x7fccbd5286f0] (active, names: '|':UITableViewCellContentView:0x7fccbd541b10 )>",
"<NSLayoutConstraint:0x600002550730 UIView:0x7fccbd5286f0.bottom == UITableViewCellContentView:0x7fccbd541b10.bottom (active)>",
"<NSLayoutConstraint:0x6000025605a0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fccbd541b10.height == 1.19209e-07 (active)>"
and below
"<NSLayoutConstraint:0x6000025505a0 V:|-(16)-[UIView:0x7fccbd5286f0] (active, names: '|':UITableViewCellContentView:0x7fccbd541b10 )>",
"<NSLayoutConstraint:0x600002550730 UIView:0x7fccbd5286f0.bottom == UITableViewCellContentView:0x7fccbd541b10.bottom (active)>",
"<NSLayoutConstraint:0x6000025605a0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fccbd541b10.height == 1.19209e-07 (active)>"
and that "Will attempt to recover by breaking constraint" for below
<NSLayoutConstraint:0x600002551a40 UIView:0x7fccbd5286f0.height == 100 (active)>
<NSLayoutConstraint:0x600002550730 UIView:0x7fccbd5286f0.bottom == UITableViewCellContentView:0x7fccbd541b10.bottom (active)>
I broke the console output into parts because I couldn't paste it all together for some reason.
Basically, I have a UIView called cellView (the white corner rounded area) inside the contentView of the cell. And all other elements you see are inside the cellView. I applied below constraints between the cellView and contentView
cellView.translatesAutoresizingMaskIntoConstraints = false
cellView.heightAnchor.constraint(equalToConstant: 100).isActive = true
cellView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 16.0).isActive = true
cellView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
cellView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16.0).isActive = true
cellView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16.0).isActive = true
It worked when I tried deactivating all constraints in the cell and its subviews just before deleting the cell. But, when new cells are reused, they didn't have constraints to activate.
How should I handle this case?
You need to lower priority of bottom constraint
let con = cellView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
con.priority = UILayoutPriority(999)
con.isActive = true
Related
I am adding a MapView (bascially a UIView) inside an empty UIStackView inside an empty UIScrollView. I implemented it the following way:
private func setupScrollView() {
scrollView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(scrollView)
let frameLayoutGuide = scrollView.frameLayoutGuide
NSLayoutConstraint.activate([
frameLayoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor),
frameLayoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor),
frameLayoutGuide.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
frameLayoutGuide.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])
}
private func setupMainStackView() {
mainStackView.axis = .vertical
mainStackView.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(mainStackView)
let contentLayoutGuide = scrollView.contentLayoutGuide
NSLayoutConstraint.activate([
mainStackView.widthAnchor.constraint(equalTo: view.widthAnchor),
mainStackView.leadingAnchor.constraint(equalTo: contentLayoutGuide.leadingAnchor),
mainStackView.trailingAnchor.constraint(equalTo: contentLayoutGuide.trailingAnchor),
mainStackView.topAnchor.constraint(equalTo: contentLayoutGuide.topAnchor),
mainStackView.bottomAnchor.constraint(equalTo: contentLayoutGuide.bottomAnchor)
])
setupMapView()
}
private func setupMapView() {
mapView.translatesAutoresizingMaskIntoConstraints = false
mapView.isUserInteractionEnabled = false
mainStackView.addArrangedSubview(mapView)
NSLayoutConstraint.activate([
// whenever the constant is set to a value other then zero, constraint issues pop up in the console
mapView.widthAnchor.constraint(equalTo: mainStackView.widthAnchor, constant: -10),
mapView.centerXAnchor.constraint(equalTo: mainStackView.centerXAnchor),
mapView.heightAnchor.constraint(equalTo: mapView.widthAnchor, multiplier: 0.618)
])
}
However, whenever the constant of the widthAnchor constraint of the mapView is set to any value other than zero, constraint issues pop up in the console. I am doing this because I want paddings on both the left and right edges of the mapView.
[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:0x282b37070 MKMapView:0x139835800.width == UIStackView:0x138a13480.width - 42.8 (active)>",
"<NSLayoutConstraint:0x282b372a0 MKMapView:0x139835800.centerX == UIStackView:0x138a13480.centerX (active)>",
"<NSLayoutConstraint:0x282b1c190 'UISV-canvas-connection' H:[MKMapView:0x139835800]-(0)-| (active, names: '|':UIStackView:0x138a13480 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x282b372a0 MKMapView:0x139835800.centerX == UIStackView:0x138a13480.centerX (active)>
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.
2020-12-26 19:01:44.048851-0800 LiQing Watercolor[16247:4990949] [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:0x282b37070 MKMapView:0x139835800.width == UIStackView:0x138a13480.width - 42.8 (active)>",
"<NSLayoutConstraint:0x282b1c140 'UISV-canvas-connection' UIStackView:0x138a13480.leading == MKMapView:0x139835800.leading (active)>",
"<NSLayoutConstraint:0x282b1c190 'UISV-canvas-connection' H:[MKMapView:0x139835800]-(0)-| (active, names: '|':UIStackView:0x138a13480 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x282b1c140 'UISV-canvas-connection' UIStackView:0x138a13480.leading == MKMapView:0x139835800.leading (active)>
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.
I also found that my code works perfectly when adding the mapView using mainStackView.addSubview(mapView) instead of mainStackView.addArrangedSubview(mapView).
If anyone knows how to resolve this issue that would be great! Thanks.
So I have a nice chart that I am adding into a tableview cell. I am trying to get this cell to always be 1/2 as tall as the width of the cell. I currently have the following constraints setup:
let cell = tableView.dequeueReusableCell(withIdentifier: "weatherCell", for: indexPath)
weatherGraph.translatesAutoresizingMaskIntoConstraints = false
cell.translatesAutoresizingMaskIntoConstraints = false
cell.contentView.addSubview(weatherGraph)
weatherGraph.leftAnchor.constraint(equalTo: cell.contentView.leftAnchor).isActive = true
weatherGraph.rightAnchor.constraint(equalTo: cell.contentView.rightAnchor).isActive = true
weatherGraph.topAnchor.constraint(equalTo: cell.contentView.topAnchor).isActive = true
weatherGraph.bottomAnchor.constraint(equalTo: cell.contentView.bottomAnchor).isActive = true
cell.contentView.heightAnchor.constraint(equalTo: cell.contentView.widthAnchor, multiplier: 0.5).isActive = true
cell.selectionStyle = .none
This way I can support resizing of the cell when the orientation of the device changes. With what I have, I am getting the following layout errors:
[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:0x60000134a210 UITableViewCellContentView:0x7fcd28866c90.height == 0.5*UITableViewCellContentView:0x7fcd28866c90.width (active)>",
"<NSLayoutConstraint:0x60000134b890 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fcd28866c90.height == 187.667 (active)>",
"<NSLayoutConstraint:0x60000134bd40 'UIView-Encapsulated-Layout-Width' UITableViewCellContentView:0x7fcd28866c90.width == 375 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000134b890 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fcd28866c90.height == 187.667 (active)>
In my heightForRowAt I am returning UITableView.automaticDimension for this specific cell.
Adding the debug message for setting the height constraint on the weatherGraph:
[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:0x600000bee030 H:|-(0)-[Digital_Heat_Sheets_Dev_2.HeatWeatherGraph:0x7fb5e0747a30](LTR) (active, names: '|':UITableViewCellContentView:0x7fb5e072cc90 )>",
"<NSLayoutConstraint:0x600000bec910 Digital_Heat_Sheets_Dev_2.HeatWeatherGraph:0x7fb5e0747a30.right == UITableViewCellContentView:0x7fb5e072cc90.right (active)>",
"<NSLayoutConstraint:0x600000bec960 V:|-(0)-[Digital_Heat_Sheets_Dev_2.HeatWeatherGraph:0x7fb5e0747a30] (active, names: '|':UITableViewCellContentView:0x7fb5e072cc90 )>",
"<NSLayoutConstraint:0x600000beca00 Digital_Heat_Sheets_Dev_2.HeatWeatherGraph:0x7fb5e0747a30.bottom == UITableViewCellContentView:0x7fb5e072cc90.bottom (active)>",
"<NSLayoutConstraint:0x600000beca50 Digital_Heat_Sheets_Dev_2.HeatWeatherGraph:0x7fb5e0747a30.height == 0.5*Digital_Heat_Sheets_Dev_2.HeatWeatherGraph:0x7fb5e0747a30.width (active)>",
"<NSLayoutConstraint:0x600000bee120 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fb5e072cc90.height == 187.667 (active)>",
"<NSLayoutConstraint:0x600000bedfe0 'UIView-Encapsulated-Layout-Width' UITableViewCellContentView:0x7fb5e072cc90.width == 375 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000beca50 Digital_Heat_Sheets_Dev_2.HeatWeatherGraph:0x7fb5e0747a30.height == 0.5*Digital_Heat_Sheets_Dev_2.HeatWeatherGraph:0x7fb5e0747a30.width (active)>
I can't figure out where the height is being set to 187.667 and why it is overriding my ratio constraint.
Have you tried setting this width-height ratio on the weather graph view itself?:
weatherGraph.heightAnchor.constraint(equalTo: weatherGraph.widthAnchor, multiplier: 0.5).isActive = true
Normally you shouldn't set any width/height constraints on the cell.contentView (or the cell itself) directly, since it's internally managed by UITableView, thus the constraints conflict.
I have a stack view that look like the figure below:
So I change the height of the image programmatically to make it fit the image that download from my server,if dont have image,the height constraints of image will set to be zero.
Here is my code to doing so:
let imageUrl = URL(string :imageString)
if let data = try? Data(contentsOf: imageUrl!)
{
guard let actualImage: UIImage = UIImage(data: data) else{
print("No image!")
ImageView.image = nil
defaultImageHeightContrainst = ImageHeightContrainst.constant
ImageHeightContrainst.constant = 0
layoutIfNeeded()
return
}
let imageHeight = actualImage.size.height * actualImage.scale
print("imageHeight = \(imageHeight)")
defaultImageHeightContrainst = ImageHeightContrainst.constant
ImageHeightContrainst.constant = imageHeight
layoutIfNeeded()
//here display the image to the imageview
ImageView.kf.setImage(with: imageUrl)
}
With the code above,the image height is scale according to actual image height which download from internet.If dont have image,the "image" part also set to 0 already.
This is what I expected,but now I face an error below whenever the "image" height become taller in order to fit the actual image height
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:0x6080002868b0 UIImageView:0x7f9cbae59240.height == 50 (active)>",
"<NSLayoutConstraint:0x608000286bd0 UIView:0x7f9cbae5ad80.height == 1 (active)>",
"<NSLayoutConstraint:0x608000286d10 UIImageView:0x7f9cbae5b440.height == 458 (active)>",
"<NSLayoutConstraint:0x608000286f90 UIView:0x7f9cbae5bb50.height == 1 (active)>",
"<NSLayoutConstraint:0x6080002871c0 V:|-(0)-[UILabel:0x7f9cbae5b160] (active, names: '|':UIStackView:0x7f9cbae5af60 )>",
"<NSLayoutConstraint:0x608000287350 V:[UILabel:0x7f9cbae5b160]-(10)-[UIImageView:0x7f9cbae5b440] (active)>",
"<NSLayoutConstraint:0x6080002873a0 V:[UIImageView:0x7f9cbae5b440]-(10)-[UIStackView:0x7f9cbae5b670] (active)>",
"<NSLayoutConstraint:0x608000287580 V:[UIStackView:0x7f9cbae5b670]-(10)-[UIView:0x7f9cbae5bb50] (active)>",
"<NSLayoutConstraint:0x6080002875d0 V:[UIStackView:0x7f9cbae5c0f0]-(0)-| (active, names: '|':UIStackView:0x7f9cbae5af60 )>",
"<NSLayoutConstraint:0x608000287670 V:[UIView:0x7f9cbae5bb50]-(10)-[UIStackView:0x7f9cbae5c0f0] (active)>",
"<NSLayoutConstraint:0x6080002877b0 V:|-(10)-[UIImageView:0x7f9cbae59240] (active, names: '|':UITableViewCellContentView:0x7f9cbae5a0c0 )>",
"<NSLayoutConstraint:0x6080002878f0 V:[UIImageView:0x7f9cbae59240]-(8)-[UIView:0x7f9cbae5ad80] (active)>",
"<NSLayoutConstraint:0x6080002879e0 V:[UIStackView:0x7f9cbae5af60]-(10)-| (active, names: '|':UITableViewCellContentView:0x7f9cbae5a0c0 )>",
"<NSLayoutConstraint:0x608000287a80 V:[UIView:0x7f9cbae5ad80]-(8)-[UIStackView:0x7f9cbae5af60] (active)>",
"<NSLayoutConstraint:0x608000288c00 'UISV-canvas-connection' UIStackView:0x7f9cbae5c0f0.top == _UILayoutSpacer:0x6080001cd5c0'UISV-alignment-spanner'.top (active)>",
"<NSLayoutConstraint:0x608000288ca0 'UISV-canvas-connection' V:[_UILayoutSpacer:0x6080001cd5c0'UISV-alignment-spanner']-(0)-| (active, names: '|':UIStackView:0x7f9cbae5c0f0 )>",
"<NSLayoutConstraint:0x608000289970 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7f9cbae5a0c0.height == 476.5 (active)>"
)
Before asking,I already checked all my other constraints,which is all set correctly.I even disable all the code that can change the height of "image",once disable,there is no problem.The error only occurred when I intend to change the height.
I even tried to add ImageView.translatesAutoresizingMaskIntoConstraints = false before layoutIfNeeded(),but the error is still exist.
So what is the correct way to change the height of image in order to fit the actual image download from server?
Considering that the last constraint says
"<NSLayoutConstraint:0x608000289970 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7f9cbae5a0c0.height == 476.5 (active)>"
I assume you are using stackView inside of a UITableViewCell to implement automatic height cells in a tableView. If my assumption is correct, then the problem is not with the stackView, nor with the imageView, but with the way UITableView works with UITableViewAutomaticDimension and Autolayout. If the layout works as you expect, and the warning is the only thing that bugs you, then read following.
Therefore it seems to me that this is a result of an known "bug" - there is a collision of the height set by the tableView and the height calculated by the autolayout. When rendering the cell, the tableView first applies the default height, calculates the autolayout height, and then use the latter - at least it seems so. See my question. The constraint mentioned above ('UIView-Encapsulated-Layout-Height') is the one applied by the UITableView that later goes away.
That means that the constraints you are using are probably OK. Just set one of the constraints defining height to priority = 999 (so that until it deactivates the default height constraint it won't cause any conflict). In the end, it will result in using your constraint anyway, so it will not cause any layout trouble.
E.g., if you constrain the stackView to fit the cell's contentView, set the stackView.bottomAnchor to contentView.bottomAnchor just with the priority set to 999. If you did the layout programmatically, this might be your solution:
let bottomConstraint = tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
bottomConstraint.priority = UILayoutPriority(rawValue: 999)
NSLayoutConstraint.activate([
// rest of the constraints
stackView.topAnchor.constraint(equalTo: contentView.topAnchor),
stackView.leftAnchor.constraint(equalTo: contentView.leftAnchor),
stackView.rightAnchor.constraint(equalTo: contentView.rightAnchor),
bottomConstraint,
])
If you do the layout in storyboards, just select appropriate constraint in the storyboards, and in the attributes inspector set its priority to 999 (for example):
Been starring at this blankly for a bit now, probably too long, so I am trying a post here.
Here's the error I am seeing:
2017-11-02 22:43:23.972361-0700 TableViewCellHeaderViewLayoutTest[88247:17250641] [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:0x60c000092930 V:|-(12)-[UILabel:0x7fd450c0eb80'Header 1'] (active, names: '|':_UITableViewHeaderFooterContentView:0x7fd450c0f290 )>",
"<NSLayoutConstraint:0x60c0000927f0 UILabel:0x7fd450c0eb80'Header 1'.bottom == _UITableViewHeaderFooterContentView:0x7fd450c0f290.bottom - 6 (active)>",
"<NSLayoutConstraint:0x60c000092ac0 'UIView-Encapsulated-Layout-Height' _UITableViewHeaderFooterContentView:0x7fd450c0f290.height == 17.5 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c0000927f0 UILabel:0x7fd450c0eb80'Header 1'.bottom == _UITableViewHeaderFooterContentView:0x7fd450c0f290.bottom - 6 (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.
It's a super simple implementation of my UITableViewHeaderFooterView subclass:
class TableViewSectionHeaderView: UITableViewHeaderFooterView {
let titleLabel = UILabel()
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
contentView.backgroundColor = .gray
titleLabel.backgroundColor = contentView.backgroundColor
titleLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
contentView.addSubview(titleLabel)
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 12).isActive = true
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 6).isActive = true
titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -6).isActive = true
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -6).isActive = true
}
}
The thing that stands out to me is this constraint:
"<NSLayoutConstraint:0x60c000092ac0 'UIView-Encapsulated-Layout-Height' _UITableViewHeaderFooterContentView:0x7fd450c0f290.height == 17.5 (active)>"
If I inspect it it also has a priority of 1000, which explains why my own constraints seems to fail.
Everything lays out fine visually, but I am concerned about that warning. What am I doing wrong?
It looks like the section header height is competing with the top and bottom constraints of the label, along with the intrinsic height of the actual label. The section header may need to grow or shrink depending on the height of the label, but the strict header height constraint is causing a conflict.
Set the sectionHeaderHeight and the estimatedSectionHeaderHeight to UITableViewAutomaticDimension to allow the height to adjust to the section's contents (the label in this case).
I have UIView with height constraint. I want to hide this view, so I set height constraint constant to 0.
I am setting constraint in code inside extended UIView:
_height = self.heightAnchor.constraint(equalToConstant: 50)
NSLayoutConstraint.activate([
_closeBtn.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 5),
_closeBtn.topAnchor.constraint(equalTo: self.topAnchor, constant: 10),
_closeBtn.heightAnchor.constraint(equalTo: _centerLabel.heightAnchor),
_closeBtn.widthAnchor.constraint(equalTo: _closeBtn.heightAnchor),
_centerLabel.topAnchor.constraint(equalTo: self.topAnchor, constant: 10),
_centerLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -5),
_centerLabel.leadingAnchor.constraint(equalTo: _closeBtn.trailingAnchor),
_centerLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -16),
_height
])
Now, If I change _height.constant = 0, I have got this error:
[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:0x146a374c0 UIButton:0x147615b00'X'.width == UIButton:0x147615b00'X'.height (active)>",
"<NSLayoutConstraint:0x146a37530 UIButton:0x147615b00'X'.height == UILabel:0x147615e80.height (active)>",
"<NSLayoutConstraint:0x146a37450 V:|-(20)-[UILabel:0x147615e80] (active, names: '|':InternetConnectionInfoView:0x14742f600 )>",
"<NSLayoutConstraint:0x146a373e0 UILabel:0x147615e80.bottom == InternetConnectionInfoView:0x14742f600.bottom - 5 (active)>",
"<NSLayoutConstraint:0x146a37680 InternetConnectionInfoView:0x14742f600.height == 0 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x146a374c0 UIButton:0x147615b00'X'.width == UIButton:0x147615b00'X'.height (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.
[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:0x146a37530 UIButton:0x147615b00'X'.height == UILabel:0x147615e80.height (active)>",
"<NSLayoutConstraint:0x146a37450 V:|-(20)-[UILabel:0x147615e80] (active, names: '|':InternetConnectionInfoView:0x14742f600 )>",
"<NSLayoutConstraint:0x146a373e0 UILabel:0x147615e80.bottom == InternetConnectionInfoView:0x14742f600.bottom - 5 (active)>",
"<NSLayoutConstraint:0x146a37680 InternetConnectionInfoView:0x14742f600.height == 0 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x146a373e0 UILabel:0x147615e80.bottom == InternetConnectionInfoView:0x14742f600.bottom - 5 (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 suspect, that this comes from top and bottom anchor being set to constant values. I have tried to use greaterThanOrEual / lessThanOrEqual, but it destroys the layout.
How to solve this (eg. hiding UIView)? I cannot set isHidden, because other UIViews are anchored to the bottom of this view and they need to move upon hiding.
This is a constraint conflict, consider reducing the constraint priority can help you fix this issue.
let closeBtnTopAnchor = _closeBtn.topAnchor.constraint(greaterThanOrEqualTo: self.topAnchor)
let closeBtnTopAnchorWithLowPriority = _closeBtn.topAnchor.constraint(equalTo: self.topAnchor, constant: 10)
closeBtnTopAnchorWithLowPriority.priority = UILayoutPriorityDefaultHigh
let centerLabelTopAnchor = _centerLabel.topAnchor.constraint(greaterThanOrEqualTo: self.topAnchor)
let centerLabelTopAnchorWithLowPriority = _centerLabel.topAnchor.constraint(equalTo: self.topAnchor, constant: 10)
centerLabelTopAnchorWithLowPriority.priority = UILayoutPriorityDefaultHigh
let centerLabelBottomAnchor = _centerLabel.bottomAnchor.constraint(lessThanOrEqualTo: self.bottomAnchor)
let centerLabelBottomAnchorWithLowPriority = _centerLabel.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -5)
centerLabelBottomAnchorWithLowPriority.priority = UILayoutPriorityDefaultHigh
NSLayoutConstraint.activate([
_closeBtn.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 5),
closeBtnTopAnchor,
closeBtnTopAnchorWithLowPriority,
_closeBtn.heightAnchor.constraint(equalTo: _centerLabel.heightAnchor),
_closeBtn.widthAnchor.constraint(equalTo: _closeBtn.heightAnchor),
centerLabelTopAnchor,
centerLabelTopAnchorWithLowPriority,
centerLabelBottomAnchor,
centerLabelBottomAnchorWithLowPriority,
_centerLabel.leadingAnchor.constraint(equalTo: _closeBtn.trailingAnchor),
_centerLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -16),
_height
])
If hiding the UIView is enough for you, how about setting its alpha to 0 ?