UILabel position in custom tableView cell - ios

I'm trying to make an app without using storyboards and I have a problem.
I've set up custom cell and everything looks ok on iPhone 5s:
But my right label looks wrong on, for example, iPhone 6s+:
Here is my code:
class CustomTableViewCell: UITableViewCell {
var leftLabel = UILabel()
var currencyValueLabel = UILabel()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
leftLabel = UILabel(frame: CGRect(
x: 16,
y: 8,
width: 100,
height: self.bounds.size.height-16
))
leftLabel.textAlignment = .Left
addSubview(leftLabel)
currencyValueLabel = UILabel(frame: CGRect(
x: self.bounds.size.width-116,
y: 8,
width: 100,
height: self.bounds.size.height-16
))
rightLabel.textAlignment = .Right
addSubview(rightLabel)
}
}
Update:
I've tried autolayout:
leftLabel.leadingAnchor.constraintEqualToAnchor(self.layoutMarginsGuide.leadingAnchor, constant: 20).active = true
leftLabel.centerYAnchor.constraintEqualToAnchor(self.layoutMarginsGuide.centerYAnchor).active = true
and this is result
2016-05-05 18:49:09.849 RubApp[57636:2228350] 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:0x7fc503d21c50 h=--& v=--& UILabel:0x7fc503cea100'EUR'.midX == + 66>",
"<NSAutoresizingMaskLayoutConstraint:0x7fc503d1ea40 h=--& v=--& H:[UILabel:0x7fc503cea100'EUR'(100)]>",
"<NSLayoutConstraint:0x7fc503ce7c00 UILabel:0x7fc503cea100'EUR'.leading == UILayoutGuide:0x7fc503ce8c20'UIViewLayoutMarginsGuide'.leading + 20>",
"<NSAutoresizingMaskLayoutConstraint:0x7fc503ce98e0 h=-&- v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[RubApp.MainViewCell:0x7fc505868000'idTableCellMainView'] (Names: '|':UITableViewWrapperView:0x7fc505869600 )>",
"<NSLayoutConstraint:0x7fc503ce7df0 'UIView-leftMargin-guide-constraint' H:|-(15)-[UILayoutGuide:0x7fc503ce8c20'UIViewLayoutMarginsGuide'](LTR) (Names: '|':RubApp.MainViewCell:0x7fc505868000'idTableCellMainView' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fc503ce7c00 UILabel:0x7fc503cea100'EUR'.leading == UILayoutGuide:0x7fc503ce8c20'UIViewLayoutMarginsGuide'.leading + 20>
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.
2016-05-05 18:49:09.857 RubApp[57636:2228350] 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:0x7fc503e5a720 h=--& v=--& UILabel:0x7fc503e49b50'USD'.midX == + 66>",
"<NSAutoresizingMaskLayoutConstraint:0x7fc503e5a940 h=--& v=--& H:[UILabel:0x7fc503e49b50'USD'(100)]>",
"<NSLayoutConstraint:0x7fc503e56f50 UILabel:0x7fc503e49b50'USD'.leading == UILayoutGuide:0x7fc503e4a3a0'UIViewLayoutMarginsGuide'.leading + 20>",
"<NSAutoresizingMaskLayoutConstraint:0x7fc503e5ab70 h=-&- v=--& 'UIView-Encapsulated-Layout-Left' H:|-(0)-[RubApp.MainViewCell:0x7fc504030a00'idTableCellMainView'] (Names: '|':UITableViewWrapperView:0x7fc505869600 )>",
"<NSLayoutConstraint:0x7fc503e4a780 'UIView-leftMargin-guide-constraint' H:|-(15)-[UILayoutGuide:0x7fc503e4a3a0'UIViewLayoutMarginsGuide'](LTR) (Names: '|':RubApp.MainViewCell:0x7fc504030a00'idTableCellMainView' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fc503e56f50 UILabel:0x7fc503e49b50'USD'.leading == UILayoutGuide:0x7fc503e4a3a0'UIViewLayoutMarginsGuide'.leading + 20>
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 know that something wrong with constant setting, but don't know what. Sorry if this question is stupid but this is my first app without storyboards.

One option is to add this line just before addSubview(rightLabel):
rightLabel.autoresizingMask = .FlexibleLeftMargin

You need to add an NSLayoutConstraint telling the label on the right hand side to have a trailing constraint of x.

Related

How to add constrains inside custom UIView?

I want to add constrainst to UILabel
My custom UIView class:
class LabelView: UIView {
public var label: UILabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
self.frame = frame
prepareUI()
}
func prepareUI() {
self.label.text = "SOME TEXT"
self.label.sizeToFit()
self.label.adjustsFontSizeToFitWidth = true
self.label.textAlignment = .center
self.addSubview(self.label)
self.translatesAutoresizingMaskIntoConstraints = false
self.label.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
self.label.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
self.label.widthAnchor.constraint(equalTo: self.widthAnchor, multiplier: 0.5).isActive = true
self.label.heightAnchor.constraint(equalTo: self.heightAnchor, multiplier: 0.2).isActive = true
}
}
after running I get the following error and the UILabel is placed in the top left corner of the UIView:
2021-02-13 02:32:26.698694+1000 SwiftHello[96793:1625524] [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:0x600000606c10 h=--& v=--& UILabel:0x142616930.minX == 0 (active, names: '|':SwiftHello.LabelView:0x1426167c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x600000606c60 h=--& v=--& UILabel:0x142616930.width == 93.5 (active)>",
"<NSLayoutConstraint:0x6000006061c0 UILabel:0x142616930.centerX == SwiftHello.LabelView:0x1426167c0.centerX (active)>",
"<NSLayoutConstraint:0x600000606300 UILabel:0x142616930.width == 0.5*SwiftHello.LabelView:0x1426167c0.width (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000006061c0 UILabel:0x142616930.centerX == SwiftHello.LabelView:0x1426167c0.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.
2021-02-13 02:32:26.698920+1000 SwiftHello[96793:1625524] [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:0x600000606cb0 h=--& v=--& UILabel:0x142616930.minY == 0 (active, names: '|':SwiftHello.LabelView:0x1426167c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x600000606d00 h=--& v=--& UILabel:0x142616930.height == 20.5 (active)>",
"<NSLayoutConstraint:0x6000006062b0 UILabel:0x142616930.centerY == SwiftHello.LabelView:0x1426167c0.centerY (active)>",
"<NSLayoutConstraint:0x600000606350 UILabel:0x142616930.height == 0.2*SwiftHello.LabelView:0x1426167c0.height (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000006062b0 UILabel:0x142616930.centerY == SwiftHello.LabelView:0x1426167c0.centerY (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.
2021-02-13 02:32:26.702639+1000 SwiftHello[96793:1625524] [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:0x600000606c60 h=--& v=--& UILabel:0x142616930.width == 93.5 (active)>",
"<NSLayoutConstraint:0x600000606300 UILabel:0x142616930.width == 0.5SwiftHello.LabelView:0x1426167c0.width (active)>",
"<NSLayoutConstraint:0x600000606940 SwiftHello.LabelView:0x1426167c0.width == 0.85UIView:0x14260e930.width (active)>",
"<NSLayoutConstraint:0x600000606da0 'UIView-Encapsulated-Layout-Width' UIView:0x14260e930.width == 375 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000606300 UILabel:0x142616930.width == 0.5*SwiftHello.LabelView:0x1426167c0.width (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.
2021-02-13 02:32:26.702816+1000 SwiftHello[96793:1625524] [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:0x600000606d00 h=--& v=--& UILabel:0x142616930.height == 20.5 (active)>",
"<NSLayoutConstraint:0x600000606350 UILabel:0x142616930.height == 0.2SwiftHello.LabelView:0x1426167c0.height (active)>",
"<NSLayoutConstraint:0x600000606990 SwiftHello.LabelView:0x1426167c0.height == 0.1UIView:0x14260e930.height (active)>",
"<NSLayoutConstraint:0x600000606d50 'UIView-Encapsulated-Layout-Height' UIView:0x14260e930.height == 667 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000606350 UILabel:0x142616930.height == 0.2*SwiftHello.LabelView:0x1426167c0.height (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.
You're missing this line:
self.label.translatesAutoresizingMaskIntoConstraints = false
You've set it on self but not on the label.

stackview constraints break when adding two views inside with imageview having fixed width and height [duplicate]

This question already has answers here:
Strange UIView-Encapsulated-Layout-Height Error
(11 answers)
Closed 2 days ago.
i have a stackview with an imageview and a label underneath it but when i try to add it into stackview it doesnt appear and apparently all the constraints break.i want the imageview to be fixed width and height and the stackview to equal the width of the label
let userView_stackView = UIStackView()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
userView_stackView.axis = .vertical
userView_stackView.alignment = .center
userView_stackView.spacing = 5
userView_stackView.addArrangedSubview(user_imageView)
userView_stackView.addArrangedSubview(user_name)
self.contentView.addSubview(userView_stackView)
stackView_constraints()
}
var user_imageView: UIImageView = {
let imageView = UIImageView()
let imageViewHeightAndWidth: CGFloat = 60
let image = UIImage(named: "steve")
imageView.image = image
imageView.layer.borderWidth = 1
imageView.clipsToBounds = true
imageView.layer.borderColor = UIColor.white.cgColor
imageView.layer.cornerRadius = imageViewHeightAndWidth / 2
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.heightAnchor.constraint(equalToConstant: imageViewHeightAndWidth).isActive = true
imageView.widthAnchor.constraint(equalToConstant: imageViewHeightAndWidth).isActive = true
return imageView
}()
var user_name: UILabel = {
let label = UILabel()
label.text = "Steve Rodriquez"
label.font = label.font.withSize(14)
return label
}()
func stackView_constraints() {
userView_stackView.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant: 0).isActive =
true
userView_stackView.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor, constant: 0)
.isActive = true
userView_stackView.trailingAnchor.constraint(
equalTo: self.contentView.trailingAnchor, constant: 0
).isActive = true
userView_stackView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 0)
.isActive = true
}
Adding views like this breaks the constraints and prints the following error on the console where all the constraints are breaking
[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:0x280d70eb0 UIStackView:0x10327c250.height == 283 (active)>",
"<NSLayoutConstraint:0x280d72580 'UIView-Encapsulated-Layout-Height' UIStackView:0x10327c250.height == 0 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280d70eb0 UIStackView:0x10327c250.height == 283 (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.
2019-10-12 10:43:30.597559-0500 Fourmi[1708:291157] [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:0x280d5f610 UIImageView:0x10327c6d0.width == 60 (active)>",
"<NSLayoutConstraint:0x280d72c10 'UISV-canvas-connection' UIStackView:0x10327c250.leading == _UILayoutSpacer:0x281174960'UISV-alignment-spanner'.leading (active)>",
"<NSLayoutConstraint:0x280d73020 'UISV-canvas-connection' UIStackView:0x10327c250.centerX == UIImageView:0x10327c6d0.centerX (active)>",
"<NSLayoutConstraint:0x280d72d50 'UISV-spanning-boundary' _UILayoutSpacer:0x281174960'UISV-alignment-spanner'.leading <= UIImageView:0x10327c6d0.leading (active)>",
"<NSLayoutConstraint:0x280d72300 'UIView-Encapsulated-Layout-Width' UIStackView:0x10327c250.width == 0 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280d5f610 UIImageView:0x10327c6d0.width == 60 (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.
2019-10-12 10:43:30.598068-0500 Fourmi[1708:291157] [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:0x280d5f5c0 UIImageView:0x10327c6d0.height == 60 (active)>",
"<NSLayoutConstraint:0x280d72b70 'UISV-canvas-connection' UIStackView:0x10327c250.top == UIImageView:0x10327c6d0.top (active)>",
"<NSLayoutConstraint:0x280d72bc0 'UISV-canvas-connection' V:[UILabel:0x10327e990'Steve Rodriquez']-(0)-| (active, names: '|':UIStackView:0x10327c250 )>",
"<NSLayoutConstraint:0x280d72c60 'UISV-spacing' V:[UIImageView:0x10327c6d0]-(5)-[UILabel:0x10327e990'Steve Rodriquez'] (active)>",
"<NSLayoutConstraint:0x280d72580 'UIView-Encapsulated-Layout-Height' UIStackView:0x10327c250.height == 0 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280d5f5c0 UIImageView:0x10327c6d0.height == 60 (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.
2019-10-12 10:43:30.598469-0500 Fourmi[1708:291157] [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:0x280d72b70 'UISV-canvas-connection' UIStackView:0x10327c250.top == UIImageView:0x10327c6d0.top (active)>",
"<NSLayoutConstraint:0x280d72bc0 'UISV-canvas-connection' V:[UILabel:0x10327e990'Steve Rodriquez']-(0)-| (active, names: '|':UIStackView:0x10327c250 )>",
"<NSLayoutConstraint:0x280d72c60 'UISV-spacing' V:[UIImageView:0x10327c6d0]-(5)-[UILabel:0x10327e990'Steve Rodriquez'] (active)>",
"<NSLayoutConstraint:0x280d72580 'UIView-Encapsulated-Layout-Height' UIStackView:0x10327c250.height == 0 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280d72c60 'UISV-spacing' V:[UIImageView:0x10327c6d0]-(5)-[UILabel:0x10327e990'Steve Rodriquez'] (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.
2019-10-12 10:43:30.598894-0500 Fourmi[1708:291157] [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:0x280d40000 h=--& v=--& UIStackView:0x10327c250.width == 0 (active)>",
"<NSLayoutConstraint:0x280d5ff20 UIStackView:0x10327c250.width == UITableViewCellContentView:0x10327fdb0.width (active)>",
"<NSLayoutConstraint:0x280d40370 'fittingSizeHTarget' UITableViewCellContentView:0x10327fdb0.width == 375 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x280d5ff20 UIStackView:0x10327c250.width == UITableViewCellContentView:0x10327fdb0.width (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.
2019-10-12 10:43:30.599762-0500 Fourmi[1708:291157] [Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view. We're considering the collapse unintentional and using standard height instead. Cell: <Fourmi.ChatTableViewCell: 0x10327af70; baseClass = UITableViewCell; frame = (0 0; 375 44); autoresize = W; layer = <CALayer: 0x282e41300>>
adding userView_stackView.translatesAutoresizingMaskIntoConstraints=falsefixed it

UIView is behind translucent navigation bar with pragmatically created view constraints

I have a function that inserts a generic UIView into a view controller at the top of the view and I would like for the inserted view to be at the bottom of a navigation bar, or if there isn't one, at the bottom of the status bar.
I assumed that the view controllers top layout guide would update automatically when it's embedded in a navigation controller, but that doesn't seem to be the case.
Here's what I have so far:
init(in viewController: UIViewController) {
super.init(frame: CGRect(x: 0, y: 0,
width: viewController.view.frame.size.width, height: 50))
initializeSubviews()
viewController.view.addSubview(self)
self.topAnchor.constraint(equalTo: viewController.topLayoutGuide.bottomAnchor, constant: 0).isActive = true
self.leadingAnchor.constraint(equalTo: viewController.view.leadingAnchor, constant: 0).isActive = true
viewController.view.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: 0).isActive = true
self.addConstraint(NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 50))
self.setNeedsLayout()
}
I can achieve this in the interface builder using a placeholder view, so I tried to use the same constraint anchors as the ones used here:
The problem is that the view is always at Y position 0 and is behind the navigation bar. I cannot change the translucency setting of the navigation bar.
I get the following errors in the console when the view is loaded:
<MyApp.MyReusableView: 0x101f3b590; frame = (0 0; 0 0); layer = <CALayer: 0x17003e720>>
2017-01-09 17:07:21.347965 MyApp[2483:984880] [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:0x1742862c0 h=--& v=--& MyApp.MyReusableView:0x101f3b590.width == 0 (active)>",
"<NSLayoutConstraint:0x1702882f0 H:|-(0)-[MyApp.MyReusableView:0x101f3b590] (active, names: '|':UIView:0x101f29f00 )>",
"<NSLayoutConstraint:0x170288340 H:[MyApp.MyReusableView:0x101f3b590]-(0)-| (active, names: '|':UIView:0x101f29f00 )>",
"<NSLayoutConstraint:0x174286450 'UIView-Encapsulated-Layout-Width' UIView:0x101f29f00.width == 375 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170288340 H:[MyApp.MyReusableView:0x101f3b590]-(0)-| (active, names: '|':UIView:0x101f29f00 )>
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-01-09 17:07:21.350923 MyApp[2483:984880] [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:0x174280a50 h=-&- v=-&- UIView:0x102b38f70.width == MyApp.MyReusableView:0x101f3b590.width (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x1742862c0 h=--& v=--& MyApp.MyReusableView:0x101f3b590.width == 0 (active)>",
"<NSLayoutConstraint:0x174286090 H:|-(16)-[UILabel:0x102b23d20'\Uf170'] (active, names: '|':UIControl:0x102b22d10 )>",
"<NSLayoutConstraint:0x174285ff0 H:[UILabel:0x102b23d20'\Uf170']-(8)-[UILabel:0x102b2efa0'Test Notification'] (active)>",
"<NSLayoutConstraint:0x174285f50 H:[UILabel:0x102b2efa0'Test Notification']-(0)-| (active, names: '|':UIControl:0x102b22d10 )>",
"<NSLayoutConstraint:0x174285cd0 H:|-(0)-[UIControl:0x102b22d10] (active, names: '|':UIView:0x102b38f70 )>",
"<NSLayoutConstraint:0x174285870 H:[UIButton:0x102b0d040'\Uf05e']-(0)-| (active, names: '|':UIView:0x102b38f70 )>",
"<NSLayoutConstraint:0x1742857d0 H:[UIControl:0x102b22d10]-(0)-[UIButton:0x102b0d040'\Uf05e'] (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174285ff0 H:[UILabel:0x102b23d20'']-(8)-[UILabel:0x102b2efa0'Test Notification'] (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-01-09 17:07:21.352456 MyApp[2483:984880] [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:0x174286360 h=--& v=--& MyApp.MyReusableView:0x101f3b590.height == 0 (active)>",
"<NSLayoutConstraint:0x170288390 MyApp.MyReusableView:0x101f3b590.height == 50 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170288390 MyApp.MyReusableView:0x101f3b590.height == 50 (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-01-09 17:07:21.354622 MyApp[2483:984880] [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)
(
"<_UILayoutSupportConstraint:0x1702877b0 _UILayoutGuide:0x101f3ae30.height == 64 (active)>",
"<_UILayoutSupportConstraint:0x17009d420 V:|-(0)-[_UILayoutGuide:0x101f3ae30] (active, names: '|':UIView:0x101f29f00 )>",
"<NSAutoresizingMaskLayoutConstraint:0x174286270 h=--& v=--& MyApp.MyReusableView:0x101f3b590.midY == 0 (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x174286360 h=--& v=--& MyApp.MyReusableView:0x101f3b590.height == 0 (active)>",
"<NSLayoutConstraint:0x170287f30 V:[_UILayoutGuide:0x101f3ae30]-(0)-[MyApp.MyReusableView:0x101f3b590] (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x174286540 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' UIView:0x101f29f00.minY == 0 (active, names: '|':UIViewControllerWrapperView:0x102b09100 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170287f30 V:[_UILayoutGuide:0x101f3ae30]-(0)-[MyApp.MyReusableView:0x101f3b590] (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-01-09 17:07:21.356571 MyApp[2483:984880] [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:0x174280a50 h=-&- v=-&- UIView:0x102b38f70.width == MyApp.MyReusableView:0x101f3b590.width (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x1742862c0 h=--& v=--& MyApp.MyReusableView:0x101f3b590.width == 0 (active)>",
"<NSLayoutConstraint:0x174285f00 UIButton:0x102b0d040'\Uf05e'.width == 50 (active)>",
"<NSLayoutConstraint:0x174285cd0 H:|-(0)-[UIControl:0x102b22d10] (active, names: '|':UIView:0x102b38f70 )>",
"<NSLayoutConstraint:0x174285870 H:[UIButton:0x102b0d040'\Uf05e']-(0)-| (active, names: '|':UIView:0x102b38f70 )>",
"<NSLayoutConstraint:0x1742857d0 H:[UIControl:0x102b22d10]-(0)-[UIButton:0x102b0d040'\Uf05e'] (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174285f00 UIButton:0x102b0d040''.width == 50 (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.
What am I doing wrong with this view constraint?
make sure that you have set translatesAutoresizingMaskIntoConstraints to false for the view and viewController.view

find a bug when try to add another UIImageView on top of the first one

I'm trying to cross-fade images when the user choose a new image filter.
So I created the secondImageView on top of the first one,and animate the alpha of the top view to show or hide the bottom view.
here is my showSecondImageView() function:
func showSecondImageView() {
view.addSubview(secondImageView)
secondImageView.translatesAutoresizingMaskIntoConstraints = false
let bottomConstraint = secondImageView.topAnchor.constraintEqualToAnchor(imageView.topAnchor)
let leftConstraint = secondImageView.leftAnchor.constraintEqualToAnchor(imageView.leftAnchor)
let rightConstraint = secondImageView.rightAnchor.constraintEqualToAnchor(imageView.rightAnchor)
let heightConstraint = secondImageView.heightAnchor.constraintEqualToAnchor(imageView.heightAnchor)
NSLayoutConstraint.activateConstraints([bottomConstraint,leftConstraint,rightConstraint,heightConstraint])
view.layoutIfNeeded()
self.secondImageView.alpha = 0
UIView.animateWithDuration(0.4) {
self.secondImageView.alpha = 1.0
}
}
the Output:
2016-02-14 23:50:17.444 Filterer[3484:344297] 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:0x7fdf58c33c80 UIImageView:0x7fdf58c30ed0.leading == UIView:0x7fdf58c22480.leading>",
"<NSLayoutConstraint:0x7fdf58c0ff70 UIImageView:0x7fdf58c30ed0.trailing == UIView:0x7fdf58c22480.trailing>",
"<NSLayoutConstraint:0x7fdf58c1d7d0 H:|-(0)-[UIView:0x7fdf58c22480] (Names: '|':UIView:0x7fdf58c19270 )>",
"<NSLayoutConstraint:0x7fdf58c1d820 H:[UIView:0x7fdf58c22480]-(0)-| (Names: '|':UIView:0x7fdf58c19270 )>",
"<NSLayoutConstraint:0x7fdf58f30850 H:[UIImageView:0x7fdf58f30440(600)]>",
"<NSLayoutConstraint:0x7fdf58c5e350 UIImageView:0x7fdf58f30440.left == UIImageView:0x7fdf58c30ed0.left>",
"<NSLayoutConstraint:0x7fdf58c79c40 UIImageView:0x7fdf58f30440.right == UIImageView:0x7fdf58c30ed0.right>",
"<NSLayoutConstraint:0x7fdf58c32190 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fdf58c19270(375)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fdf58f30850 H:[UIImageView:0x7fdf58f30440(600)]>
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.
2016-02-14 23:50:17.446 Filterer[3484:344297] 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.
(
"<_UILayoutSupportConstraint:0x7fdf58c165e0 V:[_UILayoutGuide:0x7fdf58c0fde0(0)]>",
"<_UILayoutSupportConstraint:0x7fdf58c2eb70 _UILayoutGuide:0x7fdf58c0fde0.bottom == UIView:0x7fdf58c19270.bottom>",
"<NSLayoutConstraint:0x7fdf58c35fc0 V:[UIButton:0x7fdf58c35d20'New Photo'(45)]>",
"<NSLayoutConstraint:0x7fdf58c31740 V:[UIStackView:0x7fdf58c30420]-(0)-| (Names: '|':UIView:0x7fdf58c22480 )>",
"<NSLayoutConstraint:0x7fdf58c318a0 V:|-(0)-[UIStackView:0x7fdf58c30420] (Names: '|':UIView:0x7fdf58c22480 )>",
"<NSLayoutConstraint:0x7fdf58c0ffc0 V:|-(0)-[UIImageView:0x7fdf58c30ed0] (Names: '|':UIView:0x7fdf58c19270 )>",
"<NSLayoutConstraint:0x7fdf58c26f70 V:[UIImageView:0x7fdf58c30ed0]-(0)-[UIView:0x7fdf58c22480]>",
"<NSLayoutConstraint:0x7fdf58c26fc0 V:[UIView:0x7fdf58c22480]-(0)-[_UILayoutGuide:0x7fdf58c0fde0]>",
"<NSLayoutConstraint:0x7fdf58f30ab0 V:[UIImageView:0x7fdf58f30440(555)]>",
"<NSLayoutConstraint:0x7fdf58c74640 UIImageView:0x7fdf58f30440.height == UIImageView:0x7fdf58c30ed0.height>",
"<NSLayoutConstraint:0x7fdf58c323e0 'UISV-canvas-connection' UIStackView:0x7fdf58c30420.top == UIButton:0x7fdf58c35d20'New Photo'.top>",
"<NSLayoutConstraint:0x7fdf58c3dd40 'UISV-canvas-connection' V:[UIButton:0x7fdf58c35d20'New Photo']-(0)-| (Names: '|':UIStackView:0x7fdf58c30420 )>",
"<NSLayoutConstraint:0x7fdf58c3fe60 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7fdf58c19270(667)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fdf58c35fc0 V:[UIButton:0x7fdf58c35d20'New Photo'(45)]>
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.
2016-02-14 23:50:17.461 Filterer[3484:344297] 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.
(
"<_UILayoutSupportConstraint:0x7fdf58c165e0 V:[_UILayoutGuide:0x7fdf58c0fde0(0)]>",
"<_UILayoutSupportConstraint:0x7fdf58c2eb70 _UILayoutGuide:0x7fdf58c0fde0.bottom == UIView:0x7fdf58c19270.bottom>",
"<NSLayoutConstraint:0x7fdf58c17050 V:[UIButton:0x7fdf58c16940'Edit'(45)]>",
"<NSLayoutConstraint:0x7fdf58c31740 V:[UIStackView:0x7fdf58c30420]-(0)-| (Names: '|':UIView:0x7fdf58c22480 )>",
"<NSLayoutConstraint:0x7fdf58c318a0 V:|-(0)-[UIStackView:0x7fdf58c30420] (Names: '|':UIView:0x7fdf58c22480 )>",
"<NSLayoutConstraint:0x7fdf58c0ffc0 V:|-(0)-[UIImageView:0x7fdf58c30ed0] (Names: '|':UIView:0x7fdf58c19270 )>",
"<NSLayoutConstraint:0x7fdf58c26f70 V:[UIImageView:0x7fdf58c30ed0]-(0)-[UIView:0x7fdf58c22480]>",
"<NSLayoutConstraint:0x7fdf58c26fc0 V:[UIView:0x7fdf58c22480]-(0)-[_UILayoutGuide:0x7fdf58c0fde0]>",
"<NSLayoutConstraint:0x7fdf58f30ab0 V:[UIImageView:0x7fdf58f30440(555)]>",
"<NSLayoutConstraint:0x7fdf58c74640 UIImageView:0x7fdf58f30440.height == UIImageView:0x7fdf58c30ed0.height>",
"<NSLayoutConstraint:0x7fdf58c3fa40 'UISV-alignment' UIButton:0x7fdf58c35d20'New Photo'.bottom == UIButton:0x7fdf58c16940'Edit'.bottom>",
"<NSLayoutConstraint:0x7fdf58c404d0 'UISV-alignment' UIButton:0x7fdf58c35d20'New Photo'.top == UIButton:0x7fdf58c16940'Edit'.top>",
"<NSLayoutConstraint:0x7fdf58c323e0 'UISV-canvas-connection' UIStackView:0x7fdf58c30420.top == UIButton:0x7fdf58c35d20'New Photo'.top>",
"<NSLayoutConstraint:0x7fdf58c3dd40 'UISV-canvas-connection' V:[UIButton:0x7fdf58c35d20'New Photo']-(0)-| (Names: '|':UIStackView:0x7fdf58c30420 )>",
"<NSLayoutConstraint:0x7fdf58c3fe60 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7fdf58c19270(667)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fdf58c17050 V:[UIButton:0x7fdf58c16940'Edit'(45)]>
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 first picture is the bug one,the second picture is what I want it look like,how to fix it ?
For exactly the same problem you have! I went with the UIView.transitionWithView option mentioned above:
UIView.transitionWithView( myImageView,
duration: 0.4,
options: UIViewAnimationOptions.TransitionCrossDissolve,
animations: { self.myImageView.image = toShow},
completion: { completed in
//do nothing here})
Where the variable "toShow" is the new image. This avoids the need to manage the subview.

How to let subview fill up its superview using visual format constraints?

Here's the code, I created a view and add it to self(Inherited from MKMapView):
private func setup() {
coverView = UIView()
coverView.backgroundColor = UIColor.greenColor()
coverView.layer.zPosition = 10
addSubview(coverView)
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[cover]|",
options: NSLayoutFormatOptions.allZeros,
metrics: nil,
views: ["cover": coverView]
) as! [NSLayoutConstraint])
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[cover]|",
options: NSLayoutFormatOptions.allZeros,
metrics: nil,
views: ["cover": coverView]
) as! [NSLayoutConstraint])
}
and it says:
2015-09-07 14:53:59.234 ULine[48467:825531] 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:0x7fdd23320250 H:[UIView:0x7fdd2331f860]-(10)-| (Names: '|':ULine.ULineMap:0x7fdd20e25bc0 )>",
"<NSLayoutConstraint:0x7fdd232bb840 H:[ULine.ULineMap:0x7fdd20e25bc0]-(0)-| (Names: '|':UIView:0x7fdd23320910 )>",
"<NSLayoutConstraint:0x7fdd232bb890 H:|-(0)-[ULine.ULineMap:0x7fdd20e25bc0] (Names: '|':UIView:0x7fdd23320910 )>",
"<NSAutoresizingMaskLayoutConstraint:0x7fdd232c0280 h=--& v=--& UIView:0x7fdd2331f860.midX ==>",
"<NSAutoresizingMaskLayoutConstraint:0x7fdd232c0af0 h=--& v=--& H:[UIView:0x7fdd2331f860(0)]>",
"<NSLayoutConstraint:0x7fdd237ee370 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fdd23320910(375)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fdd23320250 H:[UIView:0x7fdd2331f860]-(10)-| (Names: '|':ULine.ULineMap:0x7fdd20e25bc0 )>
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 weird, I just want it to fill up the superview.
Thanks
I solved it after I post, because of coverView enabled the "TranslatesAutoresizingMaskIntoConstraints", I just simply add coverView.setTranslatesAutoresizingMaskIntoConstraints(false), no more extra constraints added.
Hope it helps you.

Resources