I created a simple ContextMenu
override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil){ action in
let delete = UIAction(title: "Delete", image: UIImage(systemName: "trash.fill"), identifier: nil,discoverabilityTitle: nil, attributes: .destructive, handler: {action in
self.deleteItem(index: indexPath.item)
})
return UIMenu(title: "", image: nil, identifier: nil, children: [delete])
}
return configuration
}
and it causes the following warning in the console.
2020-07-16 22:58:16.227394+0200 RunPersonalRecord[8410:2186970] [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:0x280eec230 h=--& v=--& UIInterfaceActionGroupView:0x1658ca700.height == 0 (active)>",
"<NSLayoutConstraint:0x280ed7e80 groupView.actionsSequence....height >= 44 (active, names: groupView.actionsSequence...:0x158340200 )>",
"<NSLayoutConstraint:0x280ed4a00 UIInterfaceActionGroupView:0x1658ca700.top == _UIContentConstraintsLayoutGuide:0x157d4dae0''.top (active)>",
"<NSLayoutConstraint:0x280ed4140 V:[_UIContentConstraintsLayoutGuide:0x157d4dae0'']-(0)-| (active, names: '|':UIInterfaceActionGroupView:0x1658ca700 )>",
"<NSLayoutConstraint:0x280ed6710 groupView.actionsSequence....top == _UIContentConstraintsLayoutGuide:0x157d4dae0''.top (active, names: groupView.actionsSequence...:0x158340200 )>",
"<NSLayoutConstraint:0x280ed6760 groupView.actionsSequence....bottom == _UIContentConstraintsLayoutGuide:0x157d4dae0''.bottom (active, names: groupView.actionsSequence...:0x158340200 )>") Will attempt to recover by breaking constraint <NSLayoutConstraint:0x280ed7e80 groupView.actionsSequence....height >= 44 (active, names: groupView.actionsSequence...:0x158340200 )>
Could it be an apple bug or it is possible to fix somehow? Thanks!
According to apple forum it is a system bug. For now we should just ignore these warnings. Has no effect on the end user.
https://developer.apple.com/forums/thread/654647?page=1#621883022
Related
TL;DR
I want to replace a custom (different from other items) width item in UIStackView with flexible width item and center all UIStackView items.
More info:
I have a UIStackView that holds few custom UIView's:
self.handleButtonStack.axis = .horizontal
self.handleButtonStack.alignment = .center
self.handleButtonStack.distribution = .fillProportionally
self.handleButtonStack.spacing = 10.0
let hbVideo = HandleButton(image: "icon", title: "", type: .video, delegate: self)
hbVideo.widthAnchor.constraint(equalToConstant: 50).isActive = true
let hbInstagram = HandleButton(image: "icon", title: "", type: .instagram, delegate: self)
hbInstagram.widthAnchor.constraint(equalToConstant: 50).isActive = true
let hbWhatsApp = HandleButton(image: "icon", title: "", type: .whatsapp, delegate: self)
hbWhatsApp.widthAnchor.constraint(equalToConstant: 50).isActive = true
let hbHints = HandleButton(image: "icon", title: "title", type: .hint, delegate: self)
hbHints.widthAnchor.constraint(greaterThanOrEqualToConstant: 100).isActive = true
self.handleButtonStack.addArrangedSubview(hbVideo)
self.handleButtonStack.addArrangedSubview(hbInstagram)
self.handleButtonStack.addArrangedSubview(hbWhatsApp)
self.handleButtonStack.addArrangedSubview(hbHints)
After the user has preformed some action I want to change the UIStackView and remove the hbHints button and center the items.
I do that in this way:
if let subviews = self.handleButtonStack.arrangedSubviews as? [HandleButton] {
if let hintsButton = subviews.last {
self.handleButtonStack.removeFully(view: hintsButton)
let leadingSpacer = self.createSpacer(width: 50)
let trailingSpacer = self.createSpacer(width: 50)
self.handleButtonStack.insertArrangedSubview(leadingSpacer, at: 0)
self.handleButtonStack.insertArrangedSubview(trailingSpacer, at: subviews.count)
}
}
And adding a spacer like that:
func createSpacer(width: CGFloat) -> UIView {
let space = UIView(frame: .zero)
space.backgroundColor = .red
space.translatesAutoresizingMaskIntoConstraints = false
if width != 0 {
space.widthAnchor.constraint(equalToConstant: width).isActive = true
}
return space
}
My problem is that the Constraints are breaking with error and I can't figure out why. Is it possible to add a flexible width as spacer that stretch as I put it in place?
What I already tried:
Set a contentHuggingPriority to the items
Set a contentCompressionResistancePriority to the items
Adding constraints to the spacer item
Removing the width constraint for the spacer item
No success.
Here is the constraints breaking log:
[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:0x283414050 H:[UIStackView:0x124599e30]-(0)-| (active, names: '|':UIView:0x1245e9f20 )>",
"<NSLayoutConstraint:0x2834142d0 H:|-(0)-[UIStackView:0x124599e30] (active, names: '|':UIView:0x1245e9f20 )>",
"<NSLayoutConstraint:0x283416e90 UILayoutGuide:0x282e94460'UIViewSafeAreaLayoutGuide'.trailing == UIView:0x1245e9f20.trailing + 40 (active)>",
"<NSLayoutConstraint:0x283416620 UIView:0x1245e9f20.leading == UILayoutGuide:0x282e94460'UIViewSafeAreaLayoutGuide'.leading + 40 (active)>",
"<NSLayoutConstraint:0x283428b90 MyApp.HandleButton:0x124589460.width == 50 (active)>",
"<NSLayoutConstraint:0x283428af0 MyApp.HandleButton:0x124589e40.width == 50 (active)>",
"<NSLayoutConstraint:0x283428a50 MyApp.HandleButton:0x124589610.width == 50 (active)>",
"<NSLayoutConstraint:0x2834281e0 'UISV-canvas-connection' UIStackView:0x124599e30.leading == UIView:0x124576f20.leading (active)>",
"<NSLayoutConstraint:0x283428230 'UISV-canvas-connection' H:[UIView:0x1245897c0]-(0)-| (active, names: '|':UIStackView:0x124599e30 )>",
"<NSLayoutConstraint:0x2834282d0 'UISV-fill-proportionally' UIView:0x124576f20.width == 0 (active)>",
"<NSLayoutConstraint:0x28342bc50 'UISV-fill-proportionally' UIView:0x1245897c0.width == 0 (active)>",
"<NSLayoutConstraint:0x283428280 'UISV-spacing' H:[UIView:0x124576f20]-(10)-[MyApp.HandleButton:0x124589460] (active)>",
"<NSLayoutConstraint:0x28342acb0 'UISV-spacing' H:[MyApp.HandleButton:0x124589460]-(10)-[MyApp.HandleButton:0x124589e40] (active)>",
"<NSLayoutConstraint:0x28342af80 'UISV-spacing' H:[MyApp.HandleButton:0x124589e40]-(10)-[MyApp.HandleButton:0x124589610] (active)>",
"<NSLayoutConstraint:0x28342b2a0 'UISV-spacing' H:[MyApp.HandleButton:0x124589610]-(10)-[UIView:0x1245897c0] (active)>",
"<NSLayoutConstraint:0x283429810 'UIView-Encapsulated-Layout-Width' MyApp.AngleColorsView:0x124599fc0.width == 414 (active)>",
"<NSLayoutConstraint:0x283415f90 'UIViewSafeAreaLayoutGuide-left' H:|-(0)-[UILayoutGuide:0x282e94460'UIViewSafeAreaLayoutGuide'](LTR) (active, names: '|':MyApp.AngleColorsView:0x124599fc0 )>",
"<NSLayoutConstraint:0x283416440 'UIViewSafeAreaLayoutGuide-right' H:[UILayoutGuide:0x282e94460'UIViewSafeAreaLayoutGuide']-(0)-|(LTR) (active, names: '|':MyApp.AngleColorsView:0x124599fc0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x283428a50 MyApp.HandleButton:0x124589610.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 <UIKitCore/UIView.h> may also be helpful.
Here you need not give any centre alignment. As per your requirement you don't need that I think as you are giving constraints for all of your views and for the last view you are also giving greaterThanOrEqual constraint which automatically stretches your view to fill up the gaps.
So try changing the alignment from .center to .fill.
Then after you delete your last view you don't have to add any empty spacer to fill up the missing fields. Instead you can give constraints for your stack view itself.
For the leading and trailing anchor of the stack view give greaterThanOrEqualTo constraint instead of equal and also add a centre aligned constraint to the stack view.
So when you remove the view now the stack view automatically arranges the view for you in your needed centre aligned position.
Hope this is your expected end result.
expected output in GIF
I followed this tutorial of raywenderlich.com to display a context menu when long pressing on a UITableViewCell and came up with the following simplified version to test the implementation:
import UIKit
class ViewController: UITableViewController {
override func tableView(
_ tableView: UITableView,
contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint)
-> UIContextMenuConfiguration? {
let identifier = "\(indexPath.row)" as NSString
return UIContextMenuConfiguration(
identifier: identifier,
previewProvider: nil) { _ in
let shareAction = UIAction(
title: "Share",
image: UIImage(systemName: "square.and.arrow.up")) { _ in
print("share")
}
return UIMenu(title: "", image: nil, children: [shareAction])
}
}
}
The ViewController is a plain UITableViewController with Static Cells in the Storyboard. When I run the application and long press the table cell then the code works as expected, but I get the following AutoLayout errors in the console and I do not understand why?
2020-07-06 15:22:36.879780+0200 Test[1033:453998] [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:0x282308780 h=--& v=--& UIInterfaceActionGroupView:0x102833490.width == 0 (active)>",
"<NSLayoutConstraint:0x28231bca0 UILabel:0x102921c50'Share Item'.leading == UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x28231bcf0 UILabel:0x102921c50'Share Item'.trailing == UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide'.trailing (active)>",
"<NSLayoutConstraint:0x282315db0 _UIInterfaceActionGroupHeaderScrollView:0x103063600.width == _UIPreviewPlatterActionsTitleView:0x102921590'Share Item'.width (active)>",
"<NSLayoutConstraint:0x28231a800 H:|-(0)-[_UIContentConstraintsLayoutGuide:0x1028336f0''] (active, names: '|':UIInterfaceActionGroupView:0x102833490 )>",
"<NSLayoutConstraint:0x28231a850 _UIContentConstraintsLayoutGuide:0x1028336f0''.trailing == UIInterfaceActionGroupView:0x102833490.trailing (active)>",
"<NSLayoutConstraint:0x28232fd40 _UIInterfaceActionGroupHeaderScrollView:0x103063600.width == _UIContentConstraintsLayoutGuide:0x1028336f0''.width (active)>",
"<NSLayoutConstraint:0x28231cfa0 'UIView-leftMargin-guide-constraint' H:|-(12)-[UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIPreviewPlatterActionsTitleView:0x102921590'Share Item' )>",
"<NSLayoutConstraint:0x28231bc50 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide']-(12)-|(LTR) (active, names: '|':_UIPreviewPlatterActionsTitleView:0x102921590'Share Item' )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x28231bcf0 UILabel:0x102921c50'Share Item'.trailing == UILayoutGuide:0x283939420'UIViewLayoutMarginsGuide'.trailing (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2020-07-06 15:22:36.881528+0200 Test[1033:453998] [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:0x2823088c0 h=--& v=--& UIInterfaceActionGroupView:0x102833490.height == 0 (active)>",
"<NSLayoutConstraint:0x28231b070 groupView.actionsSequence....height >= 44 (active, names: groupView.actionsSequence...:0x103062e00 )>",
"<NSLayoutConstraint:0x2823135c0 V:[_UIInterfaceActionGroupHeaderScrollView:0x103063600]-(0)-[_UIInterfaceActionVibrantSeparatorView:0x10283ab40] (active)>",
"<NSLayoutConstraint:0x2823140a0 V:[_UIInterfaceActionVibrantSeparatorView:0x10283ab40]-(0)-[groupView.actionsSequence...] (active, names: groupView.actionsSequence...:0x103062e00 )>",
"<NSLayoutConstraint:0x28231ada0 UIInterfaceActionGroupView:0x102833490.top == _UIContentConstraintsLayoutGuide:0x1028336f0''.top (active)>",
"<NSLayoutConstraint:0x28231adf0 V:[_UIContentConstraintsLayoutGuide:0x1028336f0'']-(0)-| (active, names: '|':UIInterfaceActionGroupView:0x102833490 )>",
"<NSLayoutConstraint:0x282314190 _UIInterfaceActionGroupHeaderScrollView:0x103063600.top == _UIContentConstraintsLayoutGuide:0x1028336f0''.top (active)>",
"<NSLayoutConstraint:0x2823141e0 groupView.actionsSequence....bottom == _UIContentConstraintsLayoutGuide:0x1028336f0''.bottom (active, names: groupView.actionsSequence...:0x103062e00 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x28231b070 groupView.actionsSequence....height >= 44 (active, names: groupView.actionsSequence...:0x103062e00 )>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
I am using a navigation bar with a prompt, looking like this:
I receive the following auto layout warnings in the console:
2019-09-01 21:26:03.225576+0200 Hortus[85622:2386450] [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:0x600002d16990 UILabel:0x7fc9eb816f50'Testen'.centerX == _UINavigationBarModernPromptView:0x7fc9ebe27780.centerX (active)>",
"<NSLayoutConstraint:0x600002d15c20 UILabel:0x7fc9eb816f50'Testen'.leading >= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x600002d10ff0 '_UITemporaryLayoutWidth' _UINavigationBarModernPromptView:0x7fc9ebe27780.width == 0 (active)>",
"<NSLayoutConstraint:0x600002d16a30 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarModernPromptView:0x7fc9ebe27780 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600002d15c20 UILabel:0x7fc9eb816f50'Testen'.leading >= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.leading (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-09-01 21:26:03.226198+0200 Hortus[85622:2386450] [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:0x600002d16990 UILabel:0x7fc9eb816f50'Testen'.centerX == _UINavigationBarModernPromptView:0x7fc9ebe27780.centerX (active)>",
"<NSLayoutConstraint:0x600002d15540 UILabel:0x7fc9eb816f50'Testen'.trailing <= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.trailing (active)>",
"<NSLayoutConstraint:0x600002d10ff0 '_UITemporaryLayoutWidth' _UINavigationBarModernPromptView:0x7fc9ebe27780.width == 0 (active)>",
"<NSLayoutConstraint:0x600002d14320 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide']-(8)-|(LTR) (active, names: '|':_UINavigationBarModernPromptView:0x7fc9ebe27780 )>"
"<NSAutoresizingMaskLayoutConstraint:0x60000043be30 h=--& v=--& _UINavigationBarModernPromptView:0x7fb3c6416640.width == 0 (active)>",
"<NSLayoutConstraint:0x600000421400 UILabel:0x7fb3c66d8bf0'Plant guide'.centerX == _UINavigationBarModernPromptView:0x7fb3c6416640.centerX (active)>",
"<NSLayoutConstraint:0x600000421f90 UILabel:0x7fb3c66d8bf0'Plant guide'.trailing <= UILayoutGuide:0x600001e58fc0'UIViewLayoutMarginsGuide'.trailing (active)>",
"<NSLayoutConstraint:0x600000421e00 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600001e58fc0'UIViewLayoutMarginsGuide']-(20)-|(LTR) (active, names: '|':_UINavigationBarModernPromptView:0x7fb3c6416640 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600002d15540 UILabel:0x7fc9eb816f50'Testen'.trailing <= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.trailing (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.
These warnings are given for the prompt in the navigation bar, but I do not set the autolayout constraints for the navigation bar. This should be handled by IOS itself.
What can I do to fix these warnings?
[Edit] The warnings are given in prepare() when segueing to the view controller. I set the prompt in prepare(). The segue is to a storyboard reference and is defined as 'present modally'. The storyboard reference references a UINavigationController. The prompt is set on the root view controller of the navigation controller.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let identifier = segue.identifier {
switch identifier {
case "editImage":
let nc = segue.destination as? TTImageNavigationController
if let rvc = nc?.rootViewController as? TTImageEditorController {
rvc.navigationItem.prompt = navigationItem.prompt
}
default:
break
}
}
}
[EDIT] It seems that the problem is not clear to most of the people who react. Again... I do not set any auto layout settings in code or storyboard. The problem occurs in the navigation bar after setting the prompt in the prepare() function prior to the segue. The code is given above. Any reactions that say that I have to change or check my constraints are not helpful, because there are no constraints to check!
[EDIT] As requested by Mohsen, I created a small sample project on github: https://bitbucket.org/Leontien/navigationbarautolayoutwarning/src/master/
It’s not your bug. It’s Apple’s bug. Ignore the console. File a report with Apple and move on.
Set priority to your constraints. This will fulfill constraints according to priority. Please refer this link.
you set centerX for the label and set leading and trailing for right and left buttons, also you didn't set any width constraint for UILabel
"<NSLayoutConstraint:0x600002d16990 UILabel:0x7fc9eb816f50'Testen'.centerX == _UINavigationBarModernPromptView:0x7fc9ebe27780.centerX (active)>",
"<NSLayoutConstraint:0x600002d15c20 UILabel:0x7fc9eb816f50'Testen'.leading >= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x600002d10ff0 '_UITemporaryLayoutWidth' _UINavigationBarModernPromptView:0x7fc9ebe27780.width == 0 (active)>",
"<NSLayoutConstraint:0x600002d16a30 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarModernPromptView:0x7fc9ebe27780 )>"
.
"<NSLayoutConstraint:0x600002d16990 UILabel:0x7fc9eb816f50'Testen'.centerX == _UINavigationBarModernPromptView:0x7fc9ebe27780.centerX (active)>",
"<NSLayoutConstraint:0x600002d15540 UILabel:0x7fc9eb816f50'Testen'.trailing <= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.trailing (active)>",
"<NSLayoutConstraint:0x600002d10ff0 '_UITemporaryLayoutWidth' _UINavigationBarModernPromptView:0x7fc9ebe27780.width == 0 (active)>",
"<NSLayoutConstraint:0x600002d14320 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide']-(8)-|(LTR) (active, names: '|':_UINavigationBarModernPromptView:0x7fc9ebe27780 )>"
"<NSAutoresizingMaskLayoutConstraint:0x60000043be30 h=--& v=--& _UINavigationBarModernPromptView:0x7fb3c6416640.width == 0 (active)>",
"<NSLayoutConstraint:0x600000421400 UILabel:0x7fb3c66d8bf0'Plant guide'.centerX == _UINavigationBarModernPromptView:0x7fb3c6416640.centerX (active)>",
"<NSLayoutConstraint:0x600000421f90 UILabel:0x7fb3c66d8bf0'Plant guide'.trailing <= UILayoutGuide:0x600001e58fc0'UIViewLayoutMarginsGuide'.trailing (active)>",
"<NSLayoutConstraint:0x600000421e00 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600001e58fc0'UIViewLayoutMarginsGuide']-(20)-|(LTR) (active, names: '|':_UINavigationBarModernPromptView:0x7fb3c6416640 )>"
for solve this warning you should remove leading and trailing constraint from UILabel and set left button with leading to superview and right button's trailing to superview as well.
or you can use a navigation bar object, it has a label and also you can add barButtonItem to it.
you can add width constraint for the UILabel but it will be conflict on another devices when you run it on some other devices
This helps to debug broken constraint issue by providing a more readable output
Create an extension for NSLayoutConstraint
extension NSLayoutConstraint {
override open var description: String {
let id = identifier ?? ""
return "Constraint ID: \(id), constant: \(constant)"
}
}
set a unique identifier for every constraint in the storyboard
you'll get a more readable output pointing out which constraint id is broken
change the priority for broken constraint
I have a ViewController with a UIWebView, that loads a Youtube video. When I try to watch the video in fullscreen mode I get constraint errors. The video plays fine if it's not fullscreen. When I press on the fullscreen button, the video goes to fullscreen for a split second and then go back to normal mode and restart the video from the beginning. Not sure why I'm getting these errors.
Here is my ViewController class:
class VideoViewController: UIViewController {
private var webView: UIWebView!
var videoId: String? = "4YpZg-XpdAY"
override func viewDidLoad() {
super.viewDidLoad()
webView = UIWebView()
webView.allowsInlineMediaPlayback = true
webView.translatesAutoresizingMaskIntoConstraints = true
view.addSubview(webView)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if let url = URL(string: "https://www.youtube.com/watch?v=\(videoId!)") {
webView.loadRequest(URLRequest(url: url))
}
view.addConstraintsWithFormat(format: "H:|[v0]|", views: webView)
view.addConstraintsWithFormat(format: "V:|[v0]|", views: webView)
}
}
Error I'm getting in Console:
2018-10-16 02:02:21.662220-0400 Logic[2845:38866] [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:0x604000290040 h=-&- v=-&- AVPlaybackControlsView:0x7fd920c88770.width == AVPlayerViewControllerContentView:0x7fd92317b2a0.width (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x60c000094870 h=-&- v=-&- AVPlayerViewControllerContentView:0x7fd92317b2a0.width == UIView:0x7fd920e6e490.width (active)>",
"<NSLayoutConstraint:0x60c0000975c0 AVBackdropView:0x7fd920c89db0.leading == UILayoutGuide:0x60c0001b81e0'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x60c000097660 AVBackdropView:0x7fd920c8d9d0.trailing == UILayoutGuide:0x60c0001b81e0'UIViewLayoutMarginsGuide'.trailing (active)>",
"<NSLayoutConstraint:0x60c000097980 H:[AVBackdropView:0x7fd920c89db0]-(>=11)-[AVBackdropView:0x7fd920c8d9d0] (active)>",
"<NSLayoutConstraint:0x60c000099140 'UIView-Encapsulated-Layout-Width' UIView:0x7fd920e6e490.width == 0 (active)>",
"<NSLayoutConstraint:0x60c000097430 'UIView-leftMargin-guide-constraint' H:|-(6)-[UILayoutGuide:0x60c0001b81e0'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':AVPlaybackControlsView:0x7fd920c88770 )>",
"<NSLayoutConstraint:0x60c0000974d0 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x60c0001b81e0'UIViewLayoutMarginsGuide']-(6)-|(LTR) (active, names: '|':AVPlaybackControlsView:0x7fd920c88770 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60c000097980 H:[AVBackdropView:0x7fd920c89db0]-(>=11)-[AVBackdropView:0x7fd920c8d9d0] (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-10-16 02:02:21.663574-0400 Logic[2845:38866] [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:0x604000290040 h=-&- v=-&- AVPlaybackControlsView:0x7fd920c88770.width == AVPlayerViewControllerContentView:0x7fd92317b2a0.width (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x60c000094870 h=-&- v=-&- AVPlayerViewControllerContentView:0x7fd92317b2a0.width == UIView:0x7fd920e6e490.width (active)>",
"<NSLayoutConstraint:0x60c000097160 AVView:0x7fd920c8b170.width == AVTransportControlsView:0x7fd920c8b7b0.width (active)>",
"<NSLayoutConstraint:0x60c000097840 AVView:0x7fd920c8b170.width <= AVPlaybackControlsView:0x7fd920c88770.width (active)>",
"<NSLayoutConstraint:0x600000281040 AVBackdropView:0x7fd92318cc10.width <= AVTransportControlsView:0x7fd920c8b7b0.width (active)>",
"<NSLayoutConstraint:0x600000281450 H:|-(16)-[Time Elapsed](LTR) (active, names: Time Elapsed:0x7fd923134e60, '|':AVBackdropView:0x7fd92318cc10 )>",
"<NSLayoutConstraint:0x6000002814a0 Time Remaining.right == AVBackdropView:0x7fd92318cc10.right - 16 (active, names: Time Remaining:0x7fd920c460d0 )>",
"<NSLayoutConstraint:0x6000002815e0 AVScrubber:0x7fd920c8beb0.left == Time Elapsed.left (active, names: Time Elapsed:0x7fd923134e60 )>",
"<NSLayoutConstraint:0x600000281630 AVScrubber:0x7fd920c8beb0.right == Time Remaining.right (active, names: Time Remaining:0x7fd920c460d0 )>",
"<NSLayoutConstraint:0x60c000099140 'UIView-Encapsulated-Layout-Width' UIView:0x7fd920e6e490.width == 0 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000281630 AVScrubber:0x7fd920c8beb0.right == Time Remaining.right (active, names: Time Remaining:0x7fd920c460d0 )>
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.
Try this
var videoID: String? = "4YpZg-XpdAY"
guard let youtubeURL = URL(string: "https://www.youtube.com/embed/\(videoID)?rel=0&controls=0&showinfo=0&autoplay=1&allowfullscreen=1")
else { return }
webView.allowsInlineMediaPlayback = false
webView.mediaPlaybackRequiresUserAction = false
webView.mediaPlaybackAllowsAirPlay = true
webView.loadRequest( URLRequest(url: youtubeURL) )
I have a .nib for my custom header section for a table view:
override func viewDidLoad() {
super.viewDidLoad()
let nib = UINib(nibName: "BillTableSection", bundle: nil)
billTableView.register(nib, forHeaderFooterViewReuseIdentifier: "BillTableSection")
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44.0
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = billTableView.dequeueReusableHeaderFooterView(withIdentifier: "BillTableSection")
return cell
}
The custom header section works, but whenever I insert a new section, A warning shows up on my console:
2017-10-02 14:56:32.791529+0800 Project[1017:14993] [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:0x61000009f8b0 UIButton:0x7ff359d0d4a0.width == 22 (active)>",
"<NSLayoutConstraint:0x61000009f900 UITextField:0x7ff359d19660.width == UILabel:0x7ff359d17650'$0.00'.width (active)>",
"<NSLayoutConstraint:0x61000009fa90 UITextField:0x7ff359d19660.leading == UIView:0x7ff359d010a0.leadingMargin (active)>",
"<NSLayoutConstraint:0x61000009ed20 H:[UITextField:0x7ff359d19660]-(30)-[UILabel:0x7ff359d17650'$0.00'] (active)>",
"<NSLayoutConstraint:0x61000009f2c0 UIButton:0x7ff359d0d4a0.trailing == UIView:0x7ff359d010a0.trailingMargin (active)>",
"<NSLayoutConstraint:0x61000009ee60 H:[UILabel:0x7ff359d17650'$0.00']-(7)-[UIButton:0x7ff359d0d4a0] (active)>",
"<NSLayoutConstraint:0x61000009f5e0 H:[UIView:0x7ff359d010a0]-(0)-| (active, names: '|':Project.BillTableSection:0x7ff359d0fc70 )>",
"<NSLayoutConstraint:0x61000009f9a0 H:|-(0)-[UIView:0x7ff359d010a0] (active, names: '|':Project.BillTableSection:0x7ff359d0fc70 )>",
"<NSLayoutConstraint:0x61000009ff40 '_UITemporaryLayoutWidth' Project.BillTableSection:0x7ff359d0fc70.width == 0 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x61000009f8b0 UIButton:0x7ff359d0d4a0.width == 22 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
I tried to find the constraints that are not needed and remove them, but the layout I defined will not work on other devices anymore. Is it safe to ignore this warning? I'm not sure how to debug this... Please help!
You should lower the BtnAdd.trailing priority to less than 1000. it looks like autolayout adds a temporary constraint
"<NSLayoutConstraint:0x61000009ff40 '_UITemporaryLayoutWidth' Project.BillTableSection:0x7ff359d0fc70.width == 0 (active)>"
that squishes all the content, so removing that absolute priority will let your content adjust without conflicts.
Also, why is TxtName.width == LblPrice.width? Can't you adjust content hugging priority?