Resize UITableviewCell when content changes - uitableview

I have a TableViewCell with a label, a button and a hidden textfield of size 0.
If the user tapps the button the textfield should become visible. So far so good. But in console I get a constraint error during that animation because the textfield needs more space than the cell is currently sized.
How can I avoid the constraint error?
Here is my implementation:
func showTextField(show:Bool){
if show{
if textFieldHeightConstraint.constant != 200{
UIView.animate(withDuration: 0.4) { [weak self] in
self?.textFieldHeightConstraint.constant = 200
self?.feedbackTextView.isHidden = false
self?.viewModel?.refreshTableView()
}
}
}
else{
textFieldHeightConstraint.constant = 0
feedbackTextView?.text = "TODO"
feedbackTextView.isHidden = true
viewModel?.refreshTableView()
}
}
//in controller then:
func refreshTableView(){
tableView.beginUpdates()
tableView.endUpdates()
}
Constraint Error:
(
"<NSLayoutConstraint:0x600000a3fa70 UITextView:0x7f8cd4073e00'TODO'.height == 200 (active)>",
"<NSLayoutConstraint:0x600000a13020 V:|-(16)-[UILabel:0x7f8cd2e19130'M\U00f6chten Sie zu dieser Rec...'] (active, names: '|':UITableViewCellContentView:0x7f8cd2e140d0 )>",
"<NSLayoutConstraint:0x600000a0fb10 V:[UILabel:0x7f8cd2e19130'M\U00f6chten Sie zu dieser Rec...']-(8)-[UIButton:0x7f8cd2e16ea0'Add remark'] (active)>",
"<NSLayoutConstraint:0x600000a0a490 V:[UITextView:0x7f8cd4073e00'TODO']-(>=16)-| (active, names: '|':UITableViewCellContentView:0x7f8cd2e140d0 )>",
"<NSLayoutConstraint:0x600000a32440 V:[UIButton:0x7f8cd2e16ea0'Add remark']-(8)-[UITextView:0x7f8cd4073e00'TODO'] (active)>",
"<NSLayoutConstraint:0x600000a484b0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7f8cd2e140d0.height == 156 (active)>"
)

Related

iOS 16 SwiftUI keyboard safe area bug when swipe back

Maybe someone found the same bug on iOS 16
There's a strange keyboard issue on iOS 16 when pushing a new screen and trying to swipe back. The keyboard safe area is not updated when you return from the pushed screen.
Here example https://media.giphy.com/media/UaNesUynQ4O9fFBUUG/giphy.gif
var body: some View {
NavigationView {
ZStack {
VStack {
ScrollView {
ForEach(0..<40) { _ in
Color.red.frame(height: 30)
}
}
NavigationLink {
TextField("Text", text: .constant(""))
} label: {
Text("Press me")
}
}
}
}
.navigationViewStyle(.stack)
}
From XCode 14.1 I got error in logs
2022-11-02 10:33:00.540667+0200 SomeSUITestProj[22423:5008601] [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:0x283177f70 'accessoryView.bottom' _UIRemoteKeyboardPlaceholderView:0x151210eb0.bottom == _UIKBCompatInputView:0x15120d500.top (active)>",
"<NSLayoutConstraint:0x28310cd20 'assistantHeight' SystemInputAssistantView.height == 45 (active, names: SystemInputAssistantView:0x15120b840 )>",
"<NSLayoutConstraint:0x283120a50 'assistantView.bottom' SystemInputAssistantView.bottom == _UIKBCompatInputView:0x15120d500.top (active, names: SystemInputAssistantView:0x15120b840 )>",
"<NSLayoutConstraint:0x2831219f0 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x151210eb0]-(0)-[SystemInputAssistantView] (active, names: SystemInputAssistantView:0x15120b840 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x2831219f0 'assistantView.top' V:[_UIRemoteKeyboardPlaceholderView:0x151210eb0]-(0)-[SystemInputAssistantView] (active, names: SystemInputAssistantView:0x15120b840 )>
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.

UIStackView flexible width and constant width items

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

Simple UIContextMenuConfiguration causes Unable to simultaneously satisfy constraints

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

iOS UITableViewCell with UIContextMenuConfiguration: Unable to simultaneously satisfy constraints

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.

Swift 4 UIWebView Video Fullscreen Constraints error

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) )

Resources