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.

  • 相关阅读:
    Load a properties file Real's Java Howto
    [nodejs]保证你的程序死了还能复活:forever and forever webui MK2 博客园
    为嵌入式系统开发软件和为高性能计算或大型分布式平台开发软件,二者需要的技能在很大称度上相同,我不是第一个发现这一点的人。
    HTTP Range说明 lenoval的专栏 博客频道 CSDN.NET
    『NodeJS』简单的本地 DNS 代理脚本
    Automation | Coyote Point Systems
    Java 高层网络编程
    SQL 语句大全
    浅谈AVG游戏中的脚本
    How to debug Bluetooth
  • 原文地址:https://www.cnblogs.com/ioriwellings/p/6590264.html
Copyright © 2011-2022 走看看