ios - 尝试修复 UIViewAlertForUnsatisfiableConstraints 时遇到问题
问题描述
我是 iOS 开发的 100% 新手,也是我从一些承包商那里继承的项目的唯一开发人员,所以我不知道如何找出这个问题的原因。
我能够扩展输出日志以获取更多详细信息,并且我能够追踪视图,但我似乎无法找到它所指的确切组件。
UIWindow:0x7f98ce414290
| UILayoutContainerView:0x7f98ce512ad0
| | UINavigationTransitionView:0x7f98ce428970
| | | UIViewControllerWrapperView:0x7f98ce42b220
| | | | SWRevealView:0x7f98ce50b0e0
| | | | | UIView:0x7f98ce50abd0
| | | | | | UILayoutContainerView:0x7f98ce50dfb0
| | | | | | | UINavigationTransitionView:0x7f98ce614110
| | | | | | | | UIViewControllerWrapperView:0x7f98ce407440
| | | | | | | | | •UIView:0x7f98ce622790, MISSING HOST CONSTRAINTS
| | | | | | | | | | *<UILayoutGuide: 0x600003aef720 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 20}, {414, 716}}, owningView = <UIView: 0x7f98ce622790; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000d08030>; layer = <CALayer: 0x6000003d19a0>>>- AMBIGUOUS LAYOUT for UILayoutGuide:0x600003aef720'UIViewSafeAreaLayoutGuide'.Width{id: 295}, UILayoutGuide:0x600003aef720'UIViewSafeAreaLayoutGuide'.Height{id: 290}
| | | | | | | | | | *UIView:0x7f98ce621cf0
| | | | | | | | | | *UIView:0x7f98ce61e450
| | | | | | | | | | *UIView:0x7f98ce622970
| | | | | | | | | | | •UIView:0x7f98d1703b40
| | | | | | | | | | | | *<UILayoutGuide: 0x600003a997a0 - "UIViewSafeAreaLayoutGuide", layoutFrame = {{0, 0}, {320, 89.666666666666671}}, owningView = <UIView: 0x7f98d1703b40; frame = (0 0; 320 50); autoresize = W+H; tag = 10; layer = <CALayer: 0x600000385d60>>>- AMBIGUOUS LAYOUT for UILayoutGuide:0x600003a997a0'UIViewSafeAreaLayoutGuide'.Height{id: 391}
| | | | | | | | | | | | *UIButton:0x7f98ce51a5d0- AMBIGUOUS LAYOUT for UIButton:0x7f98ce51a5d0.minY{id: 404}
| | | | | | | | | | | | | UIImageView:0x7f98ce436990
| | | | | | | | | | | | *APP_NAME.CustomLabel:0x7f98ce6291f0'School Details'- AMBIGUOUS LAYOUT for APP_NAME.CustomLabel:0x7f98ce6291f0'School Details'.minY{id: 406}
| | | | | | | | | | | | *UIButton:0x7f98d1704b20- AMBIGUOUS LAYOUT for UIButton:0x7f98d1704b20.minY{id: 432}
| | | | | | | | | | | | *UIView:0x7f98d1700000- AMBIGUOUS LAYOUT for UIView:0x7f98d1700000.minY{id: 411}
| | | | | | | | | | | | *APP_NAME.CustomLabel:0x7f98ce628890
| | | | | | | | | | | | *UIImageView:0x7f98ce628660
| | | | | | | | | | *UICollectionView:0x7f98cf81fa00
| | | | | | | | | | *UIView:0x7f98ce616e90
| | | | | | | | | | | *UIStackView:0x7f98ce617070
| | | | | | | | | | | | *UIButton:0x7f98ce6101a0'NOT INTERESTED'
| | | | | | | | | | | | *UIButton:0x7f98ce60f7e0'APPLY NOW (0)'
| | | | | | | | | | | *UIView:0x7f98ce6107e0
| | | | | | | | | | *UIView:0x7f98ce621b10
| | | | | | | | | | | *UIImageView:0x7f98ce621090
| | | | | | | | | | | *UILabel:0x7f98ce6212c0'Thank you for signing up ...'
| | | | | | | | | | | *UIImageView:0x7f98ce620cb0
| | | | | | | | | | *UIView:0x7f98ce61cf60
| | | | | | | | | | | *UIImageView:0x7f98ce61c560
| | | | | | | | | | | *UILabel:0x7f98ce620270'Hang Tight!
There are no...'
| | | | | | | | | | | *APP_NAME.CustomButton:0x7f98ce6104c0'REFRESH'
| | | | | | | | | | *UIView:0x7f98ce60be10
| | | | | | | | | | *UIButton:0x7f98ce613340
| | | | | | | | | | | UIImageView:0x7f98d11144a0
| | | | | | | | | | *UIView:0x7f98ce621ed0
| | | | | | | | | | *UIView:0x7f98ce6220b0
| | | | | | | | | | | *UIImageView:0x7f98ce622290
| | | | | | | UINavigationBar:0x7f98d3804100
| | | | | | | | _UIBarBackground:0x7f98d3804520
| | | | | | | | | UIImageView:0x7f98d38049b0
| | | | | | | | | UIVisualEffectView:0x7f98d3804be0
| | | | | | | | | | _UIVisualEffectBackdropView:0x7f98ce61fdf0
| | | | | | | | | | _UIVisualEffectSubview:0x7f98ce612760
| | | | | | | | _UINavigationBarLargeTitleView:0x7f98d3805430
| | | | | | | | | UILabel:0x7f98ce50b310
| | | | | | | | •_UINavigationBarContentView:0x7f98d3805010
| | | | | | | | | *<UILayoutGuide: 0x600003a88000 - "BackButtonGuide(0x7f98d38052d0)", layoutFrame = {{0, 0}, {12, 44}}, owningView = <_UINavigationBarContentView: 0x7f98d3805010; frame = (0 0; 414 44); layer = <CALayer: 0x6000003b8840>>>
| | | | | | | | | *<UILayoutGuide: 0x600003a880e0 - "LeadingBarGuide(0x7f98d38052d0)", layoutFrame = {{12, 0}, {36, 44}}, owningView = <_UINavigationBarContentView: 0x7f98d3805010; frame = (0 0; 414 44); layer = <CALayer: 0x6000003b8840>>>
| | | | | | | | | *<UILayoutGuide: 0x600003a881c0 - "TitleView(0x7f98d38052d0)", layoutFrame = {{48, 0}, {354, 44}}, owningView = <_UINavigationBarContentView: 0x7f98d3805010; frame = (0 0; 414 44); layer = <CALayer: 0x6000003b8840>>>
| | | | | | | | | *<UILayoutGuide: 0x600003a882a0 - "TrailingBarGuide(0x7f98d38052d0)", layoutFrame = {{402, 0}, {0, 44}}, owningView = <_UINavigationBarContentView: 0x7f98d3805010; frame = (0 0; 414 44); layer = <CALayer: 0x6000003b8840>>>
| | | | | | | | | *<UILayoutGuide: 0x600003a88380 - "UIViewLayoutMarginsGuide", layoutFrame = {{20, 20}, {374, 24}}, owningView = <_UINavigationBarContentView: 0x7f98d3805010; frame = (0 0; 414 44); layer = <CALayer: 0x6000003b8840>>>
| | | | | | | | | *_UIButtonBarStackView:0x7f98d110a480
| | | | | | | | | | *<UILayoutGuide: 0x600003a94540 - "UIViewLayoutMarginsGuide", layoutFrame = {{0, 0}, {36, 44}}, owningView = <_UIButtonBarStackView: 0x7f98d110a480; frame = (12 0; 36 44); layer = <CALayer: 0x6000003e9680>>>
| | | | | | | | | | *_UIButtonBarButton:0x7f98ce40f9d0
| | | | | | | | | | | *_UIModernBarButton:0x7f98ce42fdc0
| | | | | | | | | | | | UIImageView:0x7f98ce4357d0
| | | | | | | | _UINavigationBarModernPromptView:0x7f98ce50b600
Legend:
* - is laid out with auto layout
+ - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
• - layout engine host
2019-09-02 08:36:02.740049+0900 APP_NAME[87051:13418262] [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:0x6000020c8370 UIView:0x7f98d1700000.height == 0.5 (active)>",
"<NSLayoutConstraint:0x6000020d30c0 APP_NAME.CustomLabel:0x7f98ce628890.height == 19 (active)>",
"<NSLayoutConstraint:0x6000020d1f90 UIImageView:0x7f98ce628660.height == 50 (active)>",
"<NSLayoutConstraint:0x6000020c8730 V:[UIView:0x7f98d1700000]-(0)-| (active, names: '|':UIView:0x7f98d1703b40 )>",
"<NSLayoutConstraint:0x6000020c87d0 V:[APP_NAME.CustomLabel:0x7f98ce628890]-(>=5)-[UIView:0x7f98d1700000] (active)>",
"<NSLayoutConstraint:0x6000020c8870 UIImageView:0x7f98ce628660.top == UILayoutGuide:0x600003a997a0'UIViewSafeAreaLayoutGuide'.top + 10 (active)>",
"<NSLayoutConstraint:0x6000020c8960 V:[UIImageView:0x7f98ce628660]-(5)-[APP_NAME.CustomLabel:0x7f98ce628890] (active)>",
"<NSLayoutConstraint:0x600002084b90 'UIView-Encapsulated-Layout-Height' UIView:0x7f98d1703b40.height == 50 (active)>",
"<NSLayoutConstraint:0x6000020c84b0 'UIViewSafeAreaLayoutGuide-top' V:|-(0)-[UILayoutGuide:0x600003a997a0'UIViewSafeAreaLayoutGuide'] (active, names: '|':UIView:0x7f98d1703b40 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000020d1f90 UIImageView:0x7f98ce628660.height == 50 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
例如,我可以找到UIView:0x7f98d1703b40
,但我找不到它所指的自定义标签。
任何和所有的帮助表示赞赏:-/
*****编辑*****
我终于能够将其追踪到向 UIView:0x7f98ce622790 添加导航栏的这行代码。如果我将其注释掉,错误就会消失,但导航栏会消失。
extension DIBaseController: NavigationDelegate {
func configureNavigtion(onView view: UIView, title: String?,chatTitle: String? = nil,chatImage: String? = nil, leftButtonAction leftAction: ButtonAction = .back, rightButoonTitle: String? = "" , rightButtonAction:ButtonAction = .hidden ) {
view.backgroundColor = .clear
let navBar = NavigationBar()
addChildViewController(navBar)
navBar.view.frame = view.bounds
navBar.view.tag = 10
// THIS IS THE LINE THAT CAUSES THE PROBLEM
view.addSubview(navBar.view)
navBar.configureNavigation(title,chatTitle,chatImage,leftButtonAction: leftAction,rightButoonTitle:rightButoonTitle,rightButtonAction:rightButtonAction)
navBar.delegate = self
}
@objc func navigationBar(_ navigationBar: NavigationBar,leftButtonTapped leftButton: UIButton) {
switch navigationBar.leftAction {
case .back:
navigationController?.popViewController(animated: true)
break
case .hidden,.menu:
break
default: break
}
}
@objc func navigationBar(_ navigationBar: NavigationBar,rightButtonTapped rightButton: UIButton){
}
}
NavigationBar 类看起来像这样。
protocol NavigationDelegate {
func navigationBar(_ navigationBar: NavigationBar,leftButtonTapped leftButton: UIButton)
func navigationBar(_ navigationBar: NavigationBar,rightButtonTapped rightButton: UIButton)
}
enum ButtonAction {
case back
case hidden
case menu
case chat
case option
var icon: UIImage? {
switch self {
case .back: return #imageLiteral(resourceName: "back_Arrow")
case .hidden : return nil
case .menu: return #imageLiteral(resourceName: "menu")
case .chat: return #imageLiteral(resourceName: "chatt")
case .option : return #imageLiteral(resourceName: "ic_chart_more")
}
}
}
import UIKit
class NavigationBar: UIViewController {
//MARK:-IBOulets.
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var chatUserTitle: UILabel!
@IBOutlet weak var leftButton: UIButton!
@IBOutlet weak var rightButton: UIButton!
@IBOutlet weak var chatUserImage: UIImageView!
//MARK:-Variables.
var delegate:NavigationDelegate?
var leftAction:ButtonAction = .back
var rightAction:ButtonAction = .hidden
//MARK:-ViewLifeCycle.
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Methods
//MARK: ... Public
func configureNavigation(_ title: String? = nil, _ chatTitle: String? = nil, _ chatImage: String? = nil,leftButtonAction leftAction: ButtonAction = .back,rightButoonTitle: String?,rightButtonAction: ButtonAction = .hidden) {
setupAppearance(on: leftButton, withAction: leftAction)
self.leftAction = leftAction
if let url = chatImage ,url != "" {
self.chatUserImage.isHidden = false
self.chatUserImage.kf.setImage(with: URL(string:url), placeholder: #imageLiteral(resourceName: "user_profile"), options: nil, progressBlock: nil, completionHandler: nil)
}else {
self.chatUserImage.isHidden = true
self.chatUserImage.image = #imageLiteral(resourceName: "user_profile")
}
self.titleLabel.text = title
self.chatUserTitle.text = chatTitle
if rightButoonTitle == "" {
rightButton.setTitle("", for: .normal)
setupAppearance(on: rightButton, withAction: rightButtonAction)
//rightButton.isUserInteractionEnabled = false
}else{
rightButton.isUserInteractionEnabled = true
rightButton.setTitle(rightButoonTitle, for: .normal)
}
}
func setupAppearance(on button: UIButton, withAction action: ButtonAction) -> Void {
if action == .hidden {
button.isUserInteractionEnabled = false
}else{
button.isUserInteractionEnabled = true
}
button.setImage(action.icon, for: UIControlState())
}
// MARK:- IBActions Methods
@IBAction func leftButtonTapped(_ sender: UIButton) -> Void {
delegate?.navigationBar(self, leftButtonTapped: sender)
}
@IBAction func rightButtonTapped(_ sender: UIButton) {
delegate?.navigationBar(self, rightButtonTapped: sender)
}
}
解决方案
如果我理解正确,UIView:0x7f98d1700000
和APP_NAME.CustomLabel:0x7f98ce628890
在UIImageView:0x7f98ce628660
里面UIView:0x7f98d1703b40
。图像高度设置为 50,从顶部有 10,到标签有 5,标签高度设置为 19,如果将其相加以了解内容的高度,您至少会得到 84,但是容器视图的高度仅为 50 (0x7f98d1703b40) 。
日志告诉您 84 不适合 50,因此,它必须删除约束以尝试修复错误。
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000020d1f90 UIImageView:0x7f98ce628660.height == 50 (active)>
这导致图像的高度与 50 不同。如果您对它没问题,您可以使用 Adrian 的解决方案。
如果没有,您可以增加容器视图的高度,或降低内容的高度,解决方案将取决于您想要实现的目标。
推荐阅读
- javascript - 在 NuxtJS 中的布局之间共享一个页眉/页脚
- c# - 尝试使用 selenium 和 .NET 按 ID 选择元素,但由于使用 Shadowroot 元素而出现异常 NoSuchElement
- go - 切换到新G时,P会将mcache复制到G堆栈吗?
- ms-access - 为什么 Microsoft.Jet.OLEDB.4.0 在我的计算机上抱怨 Undefined Functions 而在其他计算机上却没有?
- java - 当我尝试在 NetBeans 12 中运行 FormsFX 演示时,如何修复“缺少 JavaFX 运行时组件”Maven 错误?
- java - 使用 Spring Boot 2.2+,当应用程序不在云平台上运行时,如何创建 bean
- c# - NullReferenceException:对象引用未设置为 Unity Wave Function Collapse 中的对象实例
- cassandra - “spring data cassandra”是否有客户端负载平衡?
- excel - 如何找到范围内特定单元格的总和?
- sql - 通过引用数组保存txt文件列表[Powershell]