I have set AVPlayerViewController.How to set layout constraint for AVPlayerViewController? Thanks!
start APP console displayer this warning:
2017-04-14 10:51:34.900747 robot_blue[12510:4193750] [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:0x174482170 _UIBackdropContentView:0x101fb3e60.width == _UIBackdropView:0x101fb2990.width>",
"<NSLayoutConstraint:0x17048a8c0 UILabel:0x101fc9b00.leading == _UIBackdropContentView:0x101fb3e60.leading + 14>",
"<NSLayoutConstraint:0x17048a910 _UIBackdropContentView:0x101fb3e60.trailing == UILabel:0x101fc9b00.trailing + 14>",
"<NSLayoutConstraint:0x17048a5a0 _UIBackdropView:0x101fb2990.leading == UIView:0x101fb27f0.leading>",
"<NSLayoutConstraint:0x17048a5f0 UIView:0x101fb27f0.trailing == _UIBackdropView:0x101fb2990.trailing>",
"<NSLayoutConstraint:0x17048a410 UIView:0x101fb27f0.leading == AVAlphaUpdatingView:0x101fb2450.leading>",
"<NSLayoutConstraint:0x17048a460 AVAlphaUpdatingView:0x101fb2450.trailing == UIView:0x101fb27f0.trailing>",
"<NSLayoutConstraint:0x174482260 AVAlphaUpdatingView:0x101fb2450.width == 0>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17048a910 _UIBackdropContentView:0x101fb3e60.trailing == UILabel:0x101fc9b00.trailing + 14>
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-04-14 10:51:34.901441 robot_blue[12510:4193750] [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:0x17048a4b0 UIView:0x101fb27f0.top >= AVAlphaUpdatingView:0x101fb2450.top>",
"<NSLayoutConstraint:0x17048a500 AVAlphaUpdatingView:0x101fb2450.bottom == UIView:0x101fb27f0.bottom>",
"<NSLayoutConstraint:0x17048a550 UIView:0x101fb27f0.height == 44>",
"<NSLayoutConstraint:0x174481bd0 AVAlphaUpdatingView:0x101fb2450.height == 0>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17048a500 AVAlphaUpdatingView:0x101fb2450.bottom == UIView:0x101fb27f0.bottom>
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-04-14 10:51:34.902242 robot_blue[12510:4193750] [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:0x174482170 _UIBackdropContentView:0x101fb3e60.width == _UIBackdropView:0x101fb2990.width>",
"<NSLayoutConstraint:0x17048a6e0 UIView:0x101fb3b20.leading == _UIBackdropContentView:0x101fb3e60.leading>",
"<NSLayoutConstraint:0x17048a730 _UIBackdropContentView:0x101fb3e60.trailing == UIView:0x101fb3b20.trailing>",
"<NSLayoutConstraint:0x17048a5a0 _UIBackdropView:0x101fb2990.leading == UIView:0x101fb27f0.leading>",
"<NSLayoutConstraint:0x17048a5f0 UIView:0x101fb27f0.trailing == _UIBackdropView:0x101fb2990.trailing>",
"<NSLayoutConstraint:0x17048a410 UIView:0x101fb27f0.leading == AVAlphaUpdatingView:0x101fb2450.leading>",
"<NSLayoutConstraint:0x17048a460 AVAlphaUpdatingView:0x101fb2450.trailing == UIView:0x101fb27f0.trailing>",
"<NSLayoutConstraint:0x174482440 AVButton:0x101fb2e50.left == UIView:0x101fb3b20.left + 14>",
"<NSLayoutConstraint:0x1744824e0 UILabel:0x101fb4000.left == AVButton:0x101fb2e50.right + 15>",
"<NSLayoutConstraint:0x174482580 AVScrubber:0x101fc6900.left == UILabel:0x101fb4000.right + 12>",
"<NSLayoutConstraint:0x1744825d0 AVScrubber:0x101fc6900.right == UILabel:0x1020d1280.left - 12>",
"<NSLayoutConstraint:0x1744826c0 UILabel:0x1020d1280.right == AVButton:0x1020d1510.left - 15>",
"<NSLayoutConstraint:0x174482760 AVButton:0x1020d1510.right == AVButton:0x1020d1a30.left - 10>",
"<NSLayoutConstraint:0x174482670 AVButton:0x1020d1a30.right == AVButton:0x1020d22a0.left - 10>",
"<NSLayoutConstraint:0x174482850 AVButton:0x1020d22a0.right == UIView:0x101fb3b20.right - 14>",
"<NSLayoutConstraint:0x174482260 AVAlphaUpdatingView:0x101fb2450.width == 0>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1744824e0 UILabel:0x101fb4000.left == AVButton:0x101fb2e50.right + 15>
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-04-14 10:51:34.903110 robot_blue[12510:4193750] [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:0x174482170 _UIBackdropContentView:0x101fb3e60.width == _UIBackdropView:0x101fb2990.width>",
"<NSLayoutConstraint:0x17048a6e0 UIView:0x101fb3b20.leading == _UIBackdropContentView:0x101fb3e60.leading>",
"<NSLayoutConstraint:0x17048a730 _UIBackdropContentView:0x101fb3e60.trailing == UIView:0x101fb3b20.trailing>",
"<NSLayoutConstraint:0x17048a5a0 _UIBackdropView:0x101fb2990.leading == UIView:0x101fb27f0.leading>",
"<NSLayoutConstraint:0x17048a5f0 UIView:0x101fb27f0.trailing == _UIBackdropView:0x101fb2990.trailing>",
"<NSLayoutConstraint:0x17048a410 UIView:0x101fb27f0.leading == AVAlphaUpdatingView:0x101fb2450.leading>",
"<NSLayoutConstraint:0x17048a460 AVAlphaUpdatingView:0x101fb2450.trailing == UIView:0x101fb27f0.trailing>",
"<NSLayoutConstraint:0x174482440 AVButton:0x101fb2e50.left == UIView:0x101fb3b20.left + 14>",
"<NSLayoutConstraint:0x174482760 AVButton:0x1020d1510.right == AVButton:0x1020d1a30.left - 10>",
"<NSLayoutConstraint:0x174482670 AVButton:0x1020d1a30.right == AVButton:0x1020d22a0.left - 10>",
"<NSLayoutConstraint:0x174482850 AVButton:0x1020d22a0.right == UIView:0x101fb3b20.right - 14>",
"<NSLayoutConstraint:0x174482a80 AVLoadingIndicatorView:0x101fc8c80.left >= AVButton:0x101fb2e50.right + 15>",
"<NSLayoutConstraint:0x174482ad0 AVLoadingIndicatorView:0x101fc8c80.right <= AVButton:0x1020d1510.left - 15>",
"<NSLayoutConstraint:0x174482260 AVAlphaUpdatingView:0x101fb2450.width == 0>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x174482a80 AVLoadingIndicatorView:0x101fc8c80.left >= AVButton:0x101fb2e50.right + 15>
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.
Set the flag translatesAutoresizingMaskIntoConstraints = falseon the viewof your AVPlayerViewController. For example:
let playerViewController = AVPlayerViewController()
playerViewController.view.translatesAutoresizingMaskIntoConstraints = false
Then set your constraints on that view.
If you want the AVPlayerViewController to occupy a sub-view of your own UIViewController, then make the AVPlayerViewController a child of your view controller:
self.addChildViewController(playerViewController)
self.view.addSubview(playerViewController.view)
playerViewController.didMove(toParentViewController:self)
Related
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
}
}
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.
I am trying to constraint UITableViewCell programmatically. My cell consists of a simple pager. My init method of cell includes following.
height = UIScreen.main.bounds.width * 0.56 // If I use static i.e 320 value it is ok.
width = UIScreen.main.bounds.width is ok.
pagerView.topAnchor.constrain(to: topAnchor)
pagerView.bottomAnchor.constrain(to: bottomAnchor)
pagerView.widthAnchor.constrain(to: width)
pagerView.heightAnchor.constrain(to: height)
When I try to constraint using UIScreen.main.bounds.width it gives me following error. However, if I use static 320 value instead of UIScreen width it is all good.
> 2020-02-25 16:07:44.209043+0300 myApp[23049:780168]
> [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:0x6000035345f0 V:|-(0)-[FSPagerView.FSPagerView:0x7fb96c6226f0] (active, names:
> '|':myApp.HomePagerCell:0x7fb96e041c00'HomePagerCell' )>",
> "<NSLayoutConstraint:0x6000035346e0 FSPagerView.FSPagerView:0x7fb96c6226f0.bottom ==
> myApp.HomePagerCell:0x7fb96e041c00'HomePagerCell'.bottom (active)>",
> "<NSLayoutConstraint:0x600003534780 FSPagerView.FSPagerView:0x7fb96c6226f0.height == 231.84 (active)>",
> "<NSLayoutConstraint:0x600003534aa0 'UIView-Encapsulated-Layout-Height'
> myApp.HomePagerCell:0x7fb96e041c00'HomePagerCell'.height == 232
> (active)>" ) Will attempt to recover by breaking constraint
> <NSLayoutConstraint:0x600003534780
> FSPagerView.FSPagerView:0x7fb96c6226f0.height == 231.84 (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.
What could be the reason of it and how can I solve it?
I have an app, when I click on my profile page, I kept getting these errors in my console
I have tried
This is the entire constraint that I have on my profile page
I kept getting
john
jane
andrew
2018-07-31 11:58:46.821640-0400 tableInTabbed[4355:5682078] [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:0x604000281130 UIImageView:0x7ff91cf1d030.width == 70 (active)>",
"<NSLayoutConstraint:0x6040002812c0 UIImageView:0x7ff91cf1d030.width == UIImageView:0x7ff91cf1d030.height (active)>",
"<NSLayoutConstraint:0x604000280d20 UITableViewCellContentView:0x7ff91cf1c7f0.bottomMargin == UIImageView:0x7ff91cf1d030.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x6040002815e0 UIImageView:0x7ff91cf1d030.top == UITableViewCellContentView:0x7ff91cf1c7f0.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x60c000290040 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cf1c7f0.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6040002812c0 UIImageView:0x7ff91cf1d030.width == UIImageView:0x7ff91cf1d030.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.
2018-07-31 11:58:46.822304-0400 tableInTabbed[4355:5682078] [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:0x604000280d20 UITableViewCellContentView:0x7ff91cf1c7f0.bottomMargin == UIImageView:0x7ff91cf1d030.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x6040002815e0 UIImageView:0x7ff91cf1d030.top == UITableViewCellContentView:0x7ff91cf1c7f0.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x604000281310 UIImageView:0x7ff91cf1d030.height == 70 (active)>",
"<NSLayoutConstraint:0x60c000290040 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cf1c7f0.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x604000281310 UIImageView:0x7ff91cf1d030.height == 70 (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.
2018-07-31 11:58:46.822846-0400 tableInTabbed[4355:5682078] [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:0x60c00028fa00 UIImageView:0x7ff91cc140c0.width == 70 (active)>",
"<NSLayoutConstraint:0x60c00028ff00 UIImageView:0x7ff91cc140c0.width == UIImageView:0x7ff91cc140c0.height (active)>",
"<NSLayoutConstraint:0x60c00028a8c0 UITableViewCellContentView:0x7ff91cc13cb0.bottomMargin == UIImageView:0x7ff91cc140c0.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x60c000289b50 UIImageView:0x7ff91cc140c0.top == UITableViewCellContentView:0x7ff91cc13cb0.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x60c000290900 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cc13cb0.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c00028ff00 UIImageView:0x7ff91cc140c0.width == UIImageView:0x7ff91cc140c0.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.
2018-07-31 11:58:46.823293-0400 tableInTabbed[4355:5682078] [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:0x60c00028a8c0 UITableViewCellContentView:0x7ff91cc13cb0.bottomMargin == UIImageView:0x7ff91cc140c0.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x60c000289b50 UIImageView:0x7ff91cc140c0.top == UITableViewCellContentView:0x7ff91cc13cb0.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x60c00028fb90 UIImageView:0x7ff91cc140c0.height == 70 (active)>",
"<NSLayoutConstraint:0x60c000290900 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cc13cb0.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c00028fb90 UIImageView:0x7ff91cc140c0.height == 70 (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.
2018-07-31 11:58:46.823961-0400 tableInTabbed[4355:5682078] [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:0x60c000290ae0 UIImageView:0x7ff91cc16a40.width == 70 (active)>",
"<NSLayoutConstraint:0x60c000290b30 UIImageView:0x7ff91cc16a40.width == UIImageView:0x7ff91cc16a40.height (active)>",
"<NSLayoutConstraint:0x60c000290cc0 UITableViewCellContentView:0x7ff91cc16840.bottomMargin == UIImageView:0x7ff91cc16a40.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x60c000290d60 UIImageView:0x7ff91cc16a40.top == UITableViewCellContentView:0x7ff91cc16840.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x6040002822b0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cc16840.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c000290b30 UIImageView:0x7ff91cc16a40.width == UIImageView:0x7ff91cc16a40.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.
2018-07-31 11:58:46.824333-0400 tableInTabbed[4355:5682078] [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:0x60c000290cc0 UITableViewCellContentView:0x7ff91cc16840.bottomMargin == UIImageView:0x7ff91cc16a40.bottom + 52.67 (active)>",
"<NSLayoutConstraint:0x60c000290d60 UIImageView:0x7ff91cc16a40.top == UITableViewCellContentView:0x7ff91cc16840.topMargin + 29.33 (active)>",
"<NSLayoutConstraint:0x60c000290b80 UIImageView:0x7ff91cc16a40.height == 70 (active)>",
"<NSLayoutConstraint:0x6040002822b0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7ff91cc16840.height == 168 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c000290b80 UIImageView:0x7ff91cc16a40.height == 70 (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.
This is what I have
//
// ProfileViewController
// tableInTabbed
//
// Copyright © 2018 LR Web Design. All rights reserved.
//
import UIKit
class ProfileViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let profiles = ["john", "jane", "andrew"]
let devicesInProfile = ["3", "5", "10"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (profiles.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ViewControllerTableViewCell
cell.profileImg.image = UIImage(named: profiles[indexPath.row] + ".jpg")
cell.profileName.text = profiles[indexPath.row]
print(profiles[indexPath.row])
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
I just want to get rid of the error message.
Update
#Sandeep, after trying your answer, I ended up with this final constraint
This is the result
Can you please suggest a bit more ?
Step 1:
Drag a View to your cell and apply horizontally and vertically center constraints to to your view (This will show few constraint breaks but hang on a bit)
Step 2:
Drag imageView to view and apply height constraint/ aspect ratio/ leading / height and bottom constraint as shown
Step 3:
Drag UILabel to View preferably right side of ImageView and apply trailing constraint and leading constraint to label. Leading constraint will be to content view of cell while leading constraint to UIImageView.
Trailing Constraint to Label
Now add Leading constraint to UIImageView (Control drag from label to imageView and select horizontal spacing)
Finally control drag from label to imageView again and select center vertically
That should be it :)
If everything is fine final constraints should look like
Hope this helps
What have you did in your code seems to be fine, but it has nothing to do with what have you seen in the console.
First, you should know that red constraints means that there is something wrong, more specifically it means that the interface builder is unable to recognize what to achieve because there is at least one constraint missed (and that's why you are seeing these complains on the console).
Therefore, I would highly recommend to avoid following the approach of "Adding Missing Constraints" or "Reset to Suggested Constraints", it is not an elegant option to deal with constraints; Most of the time, even if they didn't add red (missing) constraints, it won't leads to the expected result, which seems to be logical because it can't be so magical to read your mind thoughts and translate it, they could be more than just one aspect for determining the way of how to setup the constraints! Instead, do it by your self, that's the good approach for achieving what's exactly it should look/behave. Keep in mind that it is not just one static way to do it, after getting understanding the that Auto Layout works you figure that there is more than one way to achieve it.
In general, the expected result is to see blue lines (constraints) instead of red or orange.
Now, because it might be broad to describe how to setup your constraints (Auto Layout), I would suggest to check: Understanding Auto Layout from Apple, it is a very good place to start with.
1- Make sure that only one path of elements from top to bottom is hooked to the contentView , if you see red lines , disconnect bottom constraint and change middle items constraints , then re-hook it again
2- Set bottom most constraint priority to 999
3- Set leading to the imageView and only the bottom - most element should be hooked to the contentView's bottom
//
Blue lines here should only be constraints with img width&height
//
Set this in viewDidLoad
tableView.estimatedRowHeight = 200;
tableView.rowHeight = UITableViewAutomaticDimension;
this is my view
the black area is a view, called containerView that has the following constrains
i want to add a uitableView to it dyrnamically, i did this:
func setConstraintsForTableView(tableView: UITableView){
self.containerView.addSubview(tableView)
let bottomConstraint = tableView.bottomAnchor.constraintEqualToAnchor(self.containerView.bottomAnchor)
let leftConstraint = tableView.leftAnchor.constraintEqualToAnchor(self.containerView.leftAnchor)
let rightConstraint = tableView.rightAnchor.constraintEqualToAnchor(self.containerView.rightAnchor)
let topConstraint = tableView.topAnchor.constraintEqualToAnchor(self.containerView.topAnchor)
self.containerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activateConstraints([bottomConstraint, leftConstraint, rightConstraint, topConstraint])
self.containerView.layoutIfNeeded()
}
but i got this in the log:
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:0x7fe8c9c2ddb0 h=--& v=--& UITableView:0x7fe8cd05c200.midX == + 120>",
"<NSLayoutConstraint:0x7fe8c9e97340 UIView:0x7fe8c9e8aeb0.trailingMargin == UIView:0x7fe8cb304490.trailing>",
"<NSLayoutConstraint:0x7fe8c9e97390 UIView:0x7fe8cb304490.leading == UIView:0x7fe8c9e8aeb0.leadingMargin>",
"<NSLayoutConstraint:0x7fe8c9c2cf70 H:|-(0)-[UITableView:0x7fe8cd05c200](LTR) (Names: '|':UIView:0x7fe8cb304490 )>",
"<NSLayoutConstraint:0x7fe8c9c2d0c0 UITableView:0x7fe8cd05c200.right == UIView:0x7fe8cb304490.right>",
"<NSLayoutConstraint:0x7fe8cb104c40 'UIView-Encapsulated-Layout-Width' H:[UIView:0x7fe8c9e8aeb0(375)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fe8c9c2d0c0 UITableView:0x7fe8cd05c200.right == UIView:0x7fe8cb304490.right>
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.
2015-12-19 22:12:16.201 GrabATable[2419:218311] 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:0x7fe8cb036c70 V:[_UILayoutGuide:0x7fe8c9e956a0(20)]>",
"<_UILayoutSupportConstraint:0x7fe8cb0365c0 V:|-(0)-[_UILayoutGuide:0x7fe8c9e956a0] (Names: '|':UIView:0x7fe8c9e8aeb0 )>",
"<_UILayoutSupportConstraint:0x7fe8cb0363d0 V:[_UILayoutGuide:0x7fe8c9e96410(0)]>",
"<_UILayoutSupportConstraint:0x7fe8cb018490 _UILayoutGuide:0x7fe8c9e96410.bottom == UIView:0x7fe8c9e8aeb0.bottom>",
"<NSAutoresizingMaskLayoutConstraint:0x7fe8c9c2de50 h=--& v=--& UITableView:0x7fe8cd05c200.midY == + 64>",
"<NSLayoutConstraint:0x7fe8c9e97070 UIImageView:0x7fe8c9e8a160.height == 0.33*UIView:0x7fe8c9e8aeb0.height>",
"<NSLayoutConstraint:0x7fe8c9e97110 V:[_UILayoutGuide:0x7fe8c9e956a0]-(0)-[UIImageView:0x7fe8c9e8a160]>",
"<NSLayoutConstraint:0x7fe8c9e972f0 V:[UIImageView:0x7fe8c9e8a160]-(20)-[UIView:0x7fe8cb304490]>",
"<NSLayoutConstraint:0x7fe8c9e973e0 V:[UIView:0x7fe8cb304490]-(0)-[_UILayoutGuide:0x7fe8c9e96410]>",
"<NSLayoutConstraint:0x7fe8c9c2cc50 UITableView:0x7fe8cd05c200.bottom == UIView:0x7fe8cb304490.bottom>",
"<NSLayoutConstraint:0x7fe8c9c2d210 V:|-(0)-[UITableView:0x7fe8cd05c200] (Names: '|':UIView:0x7fe8cb304490 )>",
"<NSLayoutConstraint:0x7fe8cb104c90 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7fe8c9e8aeb0(667)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fe8c9c2cc50 UITableView:0x7fe8cd05c200.bottom == UIView:0x7fe8cb304490.bottom>
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.
Output of interest:
"<NSAutoresizingMaskLayoutConstraint:0x7fe8c9c2ddb0 h=--& v=--& UITableView:0x7fe8cd05c200.midX == + 120>",
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fe8c9c2d0c0 UITableView:0x7fe8cd05c200.right == UIView:0x7fe8cb304490.right>
You need to set translatesAutoresizingMaskIntoConstraints to false on the tableView. See the UIView class Reference for more detail.
tableView.translatesAutoresizingMaskIntoConstraints = false
From the UIView Class Reference:
Discussion
If this property’s value is true, the system creates a set
of constraints that duplicate the behavior specified by the view’s
autoresizing mask. This also lets you modify the view’s size and
location using the view’s frame, bounds, or center properties,
allowing you to create a static, frame-based layout within Auto
Layout.
Note that the autoresizing mask constraints fully specify the view’s
size and position; therefore, you cannot add additional constraints to
modify this size or position without introducing conflicts. If you
want to use Auto Layout to dynamically calculate the size and position
of your view, you must set this property to false, and then provide a
non ambiguous, nonconflicting set of constraints for the view.
By default, the property is set to true for any view you
programmatically create. If you add views in Interface Builder, the
system automatically sets this property to false.