美文网首页
NSAutoresizingMaskLayoutConstrai

NSAutoresizingMaskLayoutConstrai

作者: 环宇飞杨 | 来源:发表于2019-10-29 11:21 被阅读0次

    经常遇到NSAutoresizingMaskLayoutConstraint 问题 今天这个比较特殊

    2019-10-29 10:10:59.130454+0800 TimeDB[75864:2625314] [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:0x600002f0a620 _UIToolbarContentView:0x7fb94783d340.width == 0>,
        <NSLayoutConstraint:0x600002f335c0 _UIButtonBarStackView:0x7fb94783de50.leading == _UIToolbarContentView:0x7fb94783d340.leading>,
        <NSLayoutConstraint:0x600002f33610 _UIButtonBarStackView:0x7fb94783de50.trailing == _UIToolbarContentView:0x7fb94783d340.trailing>,
        <NSLayoutConstraint:0x600002f098b0 _UIModernBarButton:0x7fb945651f20.leading == _UIButtonBarButton:0x7fb945651340.leading + 8>,
        <NSLayoutConstraint:0x600002f09900 _UIButtonBarButton:0x7fb945651340.trailing == _UIModernBarButton:0x7fb945651f20.trailing>,
        <NSLayoutConstraint:0x600002f09d60 UILayoutGuide:0x600003569c00.leading == UIView:0x7fb945650e60.leading>,
        <NSLayoutConstraint:0x600002f09ef0 UILayoutGuide:0x600003569c00.trailing == _UIButtonBarButton:0x7fb945651340.trailing>,
        <NSLayoutConstraint:0x600002f09f40 UIView:0x7fb94783bee0.leading == UIView:0x7fb945650e60.trailing>,
        <NSLayoutConstraint:0x600002f09f90 UIView:0x7fb9456511e0.leading == UIView:0x7fb94783bee0.trailing>,
        <NSLayoutConstraint:0x600002f09fe0 _UIButtonBarButton:0x7fb945651340.leading == UIView:0x7fb9456511e0.trailing>,
        <NSLayoutConstraint:0x600002f333e0 UILayoutGuide:0x600003569c00.left == _UIButtonBarStackView:0x7fb94783de50.left>,
        <NSLayoutConstraint:0x600002f33480 _UIButtonBarStackView:0x7fb94783de50.right == UILayoutGuide:0x600003569c00.right>,
    )
    
    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0x600002f09900 _UIButtonBarButton:0x7fb945651340.trailing == _UIModernBarButton:0x7fb945651f20.trailing>
    
    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.
    

    提示系统帮忙移除了<NSLayoutConstraint:0x600002f09900 _UIButtonBarButton:0x7fb945651340.trailing == _UIModernBarButton:0x7fb945651f20.trailing>,但是对这两类不熟,不清楚是哪里。
    XCode自带的布局预览不好调试,总在某一个页面报错,看样子是导航栏的问题,但注释掉很多都不起作用,一遍遍去看UINavigationBar的层级,最后注释掉了键盘弹起,才发现是IQKeyboardManager的问题,更新了下版本发现还有,应该是toolBar的布局没写好,fork下来,修复,给IQKeyboardManager提个issue,完事。

    总结下

    用来打印window下的所有视图层级,有时候应该挺实用的。

    po [[UIWindow keyWindow] _autolayoutTrace]
    

    另外expr 命令用来给地址对应的对象赋值, 比如:

    expr ((UIView*) 0x7fb94783de50).backgroungColor = [UIColor blackColor]
    

    应该也是常见的命令了,用起来这么生疏,惭愧惭愧。其实也不是什么大问题,写出来这些是因为平时遇到一些疑难杂症时都会下意识的乱试一通,今天又是如此。到头来其实效率是很差的,在试A方案的时候就想会不会是别的问题,好像知道原因了,然后中断去试,然后发现不行后又去试C方案,到头来哪个方案都没有完整的走完。有时候碰巧解决了心里感觉是哪块的问题最终也不太确定,表现出来的就是:这东西做过,但具体学到了什么,能提炼出来的就很少。

    以后遇到问题该列出几个大致可能的方向来依次去试,尤其是一些常见的小问题,往往对应着很深的知识。细细想下,伴随了五六年的小问题其实也不是什么小问题了。解决过程中要有自我存在感,过程感,要极其明确是自己在解决问题而不是任由问题牵着鼻子走,不能急躁,解决问题不是目的,目地是能讲出来问题怎么发生,自己如何判断,过程中又偏向哪些方向,要着力去记下这些东西,最后问题解决后应该花时间去总结,即便不写出来也改认真的从头到尾想一遍。

    真正的成果都在这里。

    相关文章

      网友评论

          本文标题:NSAutoresizingMaskLayoutConstrai

          本文链接:https://www.haomeiwen.com/subject/cvewvctx.html