尝试修复 UIViewAlertForUnsatisfiableConstraints 时遇到问题

Mr_Antivius

我是 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)
    }

}

Mr_Antivius

感谢 Adrian 的建议,非常感谢 cesl 的解释。

为了修复它,我不得不更改 NavigationBar 上约束的优先级。然而,由于它没有故事板并且它是通过编程完成的(我假设它是一个本地组件),我不得不遍历所有约束并将其优先级更改为较低的值,例如 200。

for constraint in navBar.view.constraints {
   constraint.priority = UILayoutPriority(200)
}

这让我可以保持约束,同时让自动布局根据需要调整组件的大小,并防止 UI 像我删除它们一样破坏自身。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

尝试安装Spacy时遇到问题

来自分类Dev

System.FormatException 错误并在尝试修复它时遇到问题

来自分类Dev

尝试在冲浪时隐藏侧边栏时遇到问题

来自分类Dev

尝试生成Doctrine2 CRUD时遇到问题

来自分类Dev

尝试调整gridworld网格时遇到问题

来自分类Dev

尝试从Firebase检索数据时遇到问题

来自分类Dev

尝试使用Pug模板的axios时遇到问题

来自分类Dev

尝试旋转SVG动画时遇到问题

来自分类Dev

尝试将元素彼此附加时遇到问题

来自分类Dev

尝试在Flutter中排序数据时遇到问题

来自分类Dev

尝试修改实例变量python时遇到问题

来自分类Dev

尝试使用vtkOBJWriter输出文件时遇到问题

来自分类Dev

尝试调整gridworld网格时遇到问题

来自分类Dev

尝试通过熊猫读取csv时遇到问题?

来自分类Dev

尝试在Ubuntu 12.04上扩展分区时遇到问题

来自分类Dev

尝试在Ubuntu上安装Telegram时遇到问题

来自分类Dev

尝试替换元组列表时遇到问题?

来自分类Dev

尝试遍历 API 数据时遇到问题

来自分类Dev

尝试使用结构变量时遇到问题

来自分类Dev

尝试使用 php artisan preset react 时遇到问题

来自分类Dev

尝试使用 RXJS 制作动态列表时遇到问题

来自分类Dev

在 Kentico 站点上实施语言可访问性修复时遇到问题

来自分类Dev

用户在初次提交后尝试重新提交时遇到问题

来自分类Dev

尝试将项目从Bitbucket导入android studio时遇到问题“存储库测试失败”

来自分类Dev

尝试随机分配测试数据库的客户名称时遇到问题

来自分类Dev

尝试使用request-html刮取JS网站时遇到问题(Python 3.6)

来自分类Dev

使用React-Router尝试根据state重定向用户时遇到问题

来自分类Dev

(Django)ForeignKey和Comment:尝试保存发布评论的用户名时遇到问题

来自分类Dev

尝试检测iOS手机是否处于静音状态时遇到问题吗?

Related 相关文章

  1. 1

    尝试安装Spacy时遇到问题

  2. 2

    System.FormatException 错误并在尝试修复它时遇到问题

  3. 3

    尝试在冲浪时隐藏侧边栏时遇到问题

  4. 4

    尝试生成Doctrine2 CRUD时遇到问题

  5. 5

    尝试调整gridworld网格时遇到问题

  6. 6

    尝试从Firebase检索数据时遇到问题

  7. 7

    尝试使用Pug模板的axios时遇到问题

  8. 8

    尝试旋转SVG动画时遇到问题

  9. 9

    尝试将元素彼此附加时遇到问题

  10. 10

    尝试在Flutter中排序数据时遇到问题

  11. 11

    尝试修改实例变量python时遇到问题

  12. 12

    尝试使用vtkOBJWriter输出文件时遇到问题

  13. 13

    尝试调整gridworld网格时遇到问题

  14. 14

    尝试通过熊猫读取csv时遇到问题?

  15. 15

    尝试在Ubuntu 12.04上扩展分区时遇到问题

  16. 16

    尝试在Ubuntu上安装Telegram时遇到问题

  17. 17

    尝试替换元组列表时遇到问题?

  18. 18

    尝试遍历 API 数据时遇到问题

  19. 19

    尝试使用结构变量时遇到问题

  20. 20

    尝试使用 php artisan preset react 时遇到问题

  21. 21

    尝试使用 RXJS 制作动态列表时遇到问题

  22. 22

    在 Kentico 站点上实施语言可访问性修复时遇到问题

  23. 23

    用户在初次提交后尝试重新提交时遇到问题

  24. 24

    尝试将项目从Bitbucket导入android studio时遇到问题“存储库测试失败”

  25. 25

    尝试随机分配测试数据库的客户名称时遇到问题

  26. 26

    尝试使用request-html刮取JS网站时遇到问题(Python 3.6)

  27. 27

    使用React-Router尝试根据state重定向用户时遇到问题

  28. 28

    (Django)ForeignKey和Comment:尝试保存发布评论的用户名时遇到问题

  29. 29

    尝试检测iOS手机是否处于静音状态时遇到问题吗?

热门标签

归档