zoukankan      html  css  js  c++  java
  • Autolayout Breakpoints

    Autolayout Breakpoints

     

    Auto layout has become a crucial tool for iOS and OS X development. It makes creating layout for multiple screen sizes easy peasy. But sometimes it can drive you crazy, with verbose and misleading logs.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    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)
    
    (...........)
    
    
    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.

    That’s a huge log! And I cut off the NSLayoutConstraint part. Yet, the second last line is giving a clue in which direction to go to fix this issue. Symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints.

    All right, here’s what Xcode want’s you to do:

    Honestly, that won’t help much, because basically it’ll just stop the execution and leave you up with LLDB, alone in the dark.

    But there’s a little trick you can do to enhance the preceding symbolic breakpoint. Adding po [[UIWindow keyWindow] _autolayoutTrace] to it (for Obj-C projects) or expr -l objc++ -O -- [[UIWindow keyWindow] _autolayoutTrace] (for Swift projects).

    Now, on console, you’ll see all the UIView hierarchy and exactly where it has ambiguity.

    1
    2
    3
    4
    5
    
    UIWindow:0x7f9481c93360
    |   UIView:0x7f9481c9d680
    |   |   *UIView:0x7f9481c9d990- AMBIGUOUS LAYOUT for UIView:0x7f9481c9d990.minX{id: 13}, UIView:0x7f9481c9d990.minY{id: 16}
    |   |   *_UILayoutGuide:0x7f9481c9e160- AMBIGUOUS LAYOUT for _UILayoutGuide:0x7f9481c9e160.minY{id: 17}
    |   |   *_UILayoutGuide:0x7f9481c9ebb0- AMBIGUOUS LAYOUT for _UILayoutGuide:0x7f9481c9ebb0.minY{id: 27}
    

    Note that as you hit continue it’ll stop at every ambiguous layout you may have. And if that’s not enough for you to find out your autolayout issue, try changing the view’s color, who knows?

    1
    2
    
    (lldb) expr ((UIView *)0x7f9ea3d43410).backgroundColor = [UIColor redColor]
    (UICachedDeviceRGBColor *) $1 = 0x00007f9ea3d43410
    

    Fear no more young Padawan, make symbolic breakpoints and LLDB work for you!

    I would like to thank Porter Hoskins for pointing out the correct LLDB command for Swift.

  • 相关阅读:
    Typora使用腾讯云图床
    2020年8月总结
    113 路径之和II
    103 二叉树的锯齿形层次遍历
    128 最长连续序列
    160 相交链表
    33 搜索旋转排序数组
    学习制作GitHub徽标
    105 从前序与中序遍历序列构造二叉树
    重新封装了layer.tips,自定义跟随弹窗
  • 原文地址:https://www.cnblogs.com/ioriwellings/p/6590264.html
Copyright © 2011-2022 走看看