iOS - can't set constraints to UIAlertController with progressView - ios

I have tried to place the progressView inside UIAlertController using constraints in order to get a good visual result on iPhone or iPad.
alert = [UIAlertController
alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* cancelButton = [UIAlertAction
actionWithTitle:titleCancel
style:UIAlertActionStyleDefault
handler:cancelBlock];
[alert addAction:cancelButton];
UIProgressView* progressView = [[UIProgressView alloc] init];
progressView.progress = 0.0;
progressView.tintColor = UIColor.blueColor;
[alert.view addSubview:progressView];
UILayoutGuide *margin = alert.view.layoutMarginsGuide;
[alert.view setAutoresizingMask:UIViewAutoresizingNone];
[progressView.heightAnchor constraintEqualToConstant:5].active = YES;
[progressView.widthAnchor constraintEqualToAnchor:margin.widthAnchor multiplier:0.75].active = YES;
[progressView.centerXAnchor constraintEqualToAnchor:margin.centerXAnchor].active = YES;
[progressView.centerYAnchor constraintEqualToAnchor:margin.centerYAnchor].active = YES;
[self presentViewController:alert animated:YES completion:nil];
I want to achieve something like this(que purple square is supuse the alertViewController, is just an example...):
This is the logs... what I'm doing wrong... why are there conflicts with constraints?
2017-05-09 18:17:28.657982 Myapp[1457:1442554] [Common] _BSMachError: port a0a3; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
2017-05-09 18:17:28.659300 Myapp[1457:1442554] [Common] _BSMachError: port a0a3; (os/kern) invalid name (0xf) "Unable to deallocate send right"
2017-05-09 18:17:28.709082 Myapp[1457:1442554] [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:0x17048be00 h=--& v=--& UIProgressView:0x1013a44b0.height == 2 (active)>",
"<NSLayoutConstraint:0x17449cb60 UIProgressView:0x1013a44b0.height == 5 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17449cb60 UIProgressView:0x1013a44b0.height == 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.
2017-05-09 18:17:28.712681 Myapp[1457:1442554] [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:0x170490310 h=--& v=--& UIProgressView:0x1013a44b0.midY == 1 (active)>",
"<NSLayoutConstraint:0x17449fef0 UIView:0x1013a56e0.height >= 44 (active)>",
"<NSLayoutConstraint:0x17449b2b0 _UIAlertControllerView:0x1013a5a40'Myapp'.height == UIView:0x1013a56e0.height (active)>",
"<NSLayoutConstraint:0x174681e50 UIProgressView:0x1013a44b0.centerY == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerY (active)>",
"<NSLayoutConstraint:0x174681e00 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide']-(8)-| (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>",
"<NSLayoutConstraint:0x174681bd0 'UIView-topMargin-guide-constraint' V:|-(8)-[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'] (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17449fef0 UIView:0x1013a56e0.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.
2017-05-09 18:17:28.715180 Myapp[1457:1442554] [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:0x170490310 h=--& v=--& UIProgressView:0x1013a44b0.midY == 1 (active)>",
"<NSLayoutConstraint:0x174681e50 UIProgressView:0x1013a44b0.centerY == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerY (active)>",
"<NSLayoutConstraint:0x174681bd0 'UIView-topMargin-guide-constraint' V:|-(8)-[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'] (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174681e50 UIProgressView:0x1013a44b0.centerY == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerY (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-05-09 18:17:28.717844 Myapp[1457:1442554] [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:0x170490f40 h=--& v=--& UIProgressView:0x1013a44b0.midX == 0 (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x170495270 h=--& v=--& UIProgressView:0x1013a44b0.width == 0 (active)>",
"<NSLayoutConstraint:0x174681db0 UIProgressView:0x1013a44b0.width == 0.75*UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.width (active)>",
"<NSLayoutConstraint:0x174681f40 UIProgressView:0x1013a44b0.centerX == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerX (active)>",
"<NSLayoutConstraint:0x174681c20 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174681f40 UIProgressView:0x1013a44b0.centerX == UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.centerX (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-05-09 18:17:28.720158 Myapp[1457:1442554] [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:0x170495270 h=--& v=--& UIProgressView:0x1013a44b0.width == 0 (active)>",
"<NSLayoutConstraint:0x170288840 UIView:0x1013a56e0.width == 270 (active)>",
"<NSLayoutConstraint:0x174499eb0 _UIAlertControllerView:0x1013a5a40'Myapp'.width >= UIView:0x1013a56e0.width (active)>",
"<NSLayoutConstraint:0x174681db0 UIProgressView:0x1013a44b0.width == 0.75*UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'.width (active)>",
"<NSLayoutConstraint:0x174681c20 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>",
"<NSLayoutConstraint:0x174681f90 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x174389170'UIViewLayoutMarginsGuide']-(8)-|(LTR) (active, names: '|':_UIAlertControllerView:0x1013a5a40'Myapp' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170288840 UIView:0x1013a56e0.width == 270 (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.

First of all, I don't think adding constraints to progress view is a good idea. Since it is added to the UIAlertController which is presented.
If you are adding a progressView, You need to track the progress and update the Progress which needs to be done on the main thread, So every time any heavy operation is going on it might affect the UI Update(progress). This has to be handled properly by GCD
Below approach will help to achieve solution to your problem
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController * alertCont = [UIAlertController alertControllerWithTitle:#"Test" message:#"Test message" preferredStyle:UIAlertControllerStyleAlert];
UIProgressView * progresbar = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
[progresbar setProgress:5.0 animated:YES];
progresbar.frame = CGRectMake(10, 40, 250, 0);
[alertCont.view addSubview:progresbar];
[topController presentViewController:alertCont animated:YES completion:nil];
});

You should not set constraints relative to AlertviewController's view. Instead use AlertviewController -> View -> Subviews[0] to set constraint.
For example, to set width of UIAlertController:
for constraint in self.alertView.subviews[0].constraints {
if constraint.firstAttribute == NSLayoutAttribute.width && constraint.constant == 270{
NSLayoutConstraint.deactivate([constraint])
break
}
}
let widthConstraint:NSLayoutConstraint = NSLayoutConstraint(item: self.view.subviews[0], attribute:
NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 120.0)
self.alertview.subviews[0].addConstraint(widthConstraint)

Related

DatePicker with graphical style breaks layout constraints on iOS 16.0

The following code breaks the layout constraints when running on Xcode-14.0.0-Beta 5 with iOS 16.0
struct ContentView: View {
#State var date = Date()
var body: some View {
DatePicker(selection: $date, displayedComponents: .date, label: { EmptyView() })
.datePickerStyle(.graphical)
}
}
Any suggestions how to fix or hide the warning?
Console warning:
2022-08-24 17:16:40.471325+0300 DatePickerProblem[77364:483284] [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:0x600003559180 h=--& v=--& _UIDatePickerCalendarTimeView:0x7fe15c322520.height == 0 (active)>",
"<NSLayoutConstraint:0x60000352bca0 _UIDatePickerCompactTimeLabel:0x7fe15c322bc0.centerY == _UIDatePickerCalendarTimeView:0x7fe15c322520.centerY - 1 (active)>",
"<NSLayoutConstraint:0x60000352bcf0 V:|-(>=0)-[_UIDatePickerCompactTimeLabel:0x7fe15c322bc0] (active, names: '|':_UIDatePickerCalendarTimeView:0x7fe15c322520 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000352bca0 _UIDatePickerCompactTimeLabel:0x7fe15c322bc0.centerY == _UIDatePickerCalendarTimeView:0x7fe15c322520.centerY - 1 (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.
2022-08-24 17:16:40.471971+0300 DatePickerProblem[77364:483284] [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:0x600003559180 h=--& v=--& _UIDatePickerCalendarTimeView:0x7fe15c322520.height == 0 (active)>",
"<NSLayoutConstraint:0x60000352bd40 UILabel:0x7fe15c324d00.centerY == _UIDatePickerCalendarTimeView:0x7fe15c322520.centerY - 1 (active)>",
"<NSLayoutConstraint:0x60000352bd90 V:|-(>=0)-[UILabel:0x7fe15c324d00] (active, names: '|':_UIDatePickerCalendarTimeView:0x7fe15c322520 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60000352bd40 UILabel:0x7fe15c324d00.centerY == _UIDatePickerCalendarTimeView:0x7fe15c322520.centerY - 1 (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.
2022-08-24 17:16:40.478778+0300 DatePickerProblem[77364:483284] [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)
(
"<_UISystemBaselineConstraint:0x60000355c190 H:[UILabel:0x7fe15c324d00]-(>=NSLayoutAnchorConstraintSpace(8))-[_UIDatePickerCompactTimeLabel:0x7fe15c322bc0] (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x6000035590e0 h=--& v=--& _UIDatePickerCalendarTimeView:0x7fe15c322520.width == 0 (active)>",
"<NSLayoutConstraint:0x60000352bf20 UILabel:0x7fe15c324d00.leading == UILayoutGuide:0x600002f06760'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x60000355c230 _UIDatePickerCompactTimeLabel:0x7fe15c322bc0.trailing == UILayoutGuide:0x600002f06760'UIViewLayoutMarginsGuide'.trailing (active)>",
"<NSLayoutConstraint:0x60000352be30 'UIView-leftMargin-guide-constraint' H:|-(8)-UILayoutGuide:0x600002f06760'UIViewLayoutMarginsGuide' (active, names: '|':_UIDatePickerCalendarTimeView:0x7fe15c322520 )>",
"<NSLayoutConstraint:0x60000352bed0 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600002f06760'UIViewLayoutMarginsGuide']-(8)-|(LTR) (active, names: '|':_UIDatePickerCalendarTimeView:0x7fe15c322520 )>"
)
Will attempt to recover by breaking constraint
<_UISystemBaselineConstraint:0x60000355c190 H:[UILabel:0x7fe15c324d00]-(>=NSLayoutAnchorConstraintSpace(8))-[_UIDatePickerCompactTimeLabel:0x7fe15c322bc0] (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.
2022-08-24 17:16:40.512015+0300 DatePickerProblem[77364:483284] [UICalendarView] UICalendarView's height is smaller than it can render its content in; defaulting to the minimum height.
2022-08-24 17:16:40.548888+0300 DatePickerProblem[77364:483284] [UICalendarView] UICalendarView's height is smaller than it can render its content in; defaulting to the minimum height.
It seems that the new underlying UICalendarView has some AutoLayout Issues when used by its SwiftUI DatePicker wrapper.
You can see this even better, when you enable the Time Component too (displayedComponents: [.date, .hourAndMinute]). This gives a much longer Auto-Layout warning about the time label constraint being broken.
For me this happens especially when the SwiftUI View is embedded using an UIHostingController which is pushed onto a Navigation Stack.
In my case, I was able to fix it by giving the DatePicker its default width as its frame width:
struct ContentView: View {
#State var date = Date()
var body: some View {
DatePicker(
selection: $date,
displayedComponents: [.date, .hourAndMinute],
label: { EmptyView() }
)
.datePickerStyle(.graphical)
.frame(width: 320) // Bugfix for AutoLayout-Issue
}
}

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.

Resources