iPhone — is it possible to inspect the frame of a UIView in the Xcode debugger?

前端 未结 12 559
执念已碎
执念已碎 2021-02-02 08:18

When the debugger is stopped at a breakpoint, I can\'t find the frame of any of my UIViews in there.

Is it possible to do this?

EDIT: starting a bounty due to th

相关标签:
12条回答
  • 2021-02-02 08:20
    po [[[[UIApplication sharedApplication]windows] objectAtIndex:0] recursiveDescription]
    

    will print out the entire view heirachy but only seems to work in gdb and not llvm

    0 讨论(0)
  • 2021-02-02 08:24

    In Xcode, go to the console and type:

    po viewName
    

    If execution is inside code for the view, you can just:

    po self
    

    This will output some view details, like this:

    <UIView: 0x9cca0f0; frame = (0 0; 320 480); layer = <CALayer: 0x9ccabe0>>
    
    0 讨论(0)
  • 2021-02-02 08:26

    Found an answer for lldb. For example, this works

    (lldb) print (CGRect)[((UIView *)[[[self backIV] subviews] objectAtIndex:1]) frame]
    
    0 讨论(0)
  • 2021-02-02 08:27

    Re-formatting @EPage_Ed's answer because the original was hard-coded for his specific case:

    At the (lldb) prompt, type:

    print (CGRect)[view frame]
    

    Or, for the bounds:

    print (CGRect)[view bounds]
    
    0 讨论(0)
  • 2021-02-02 08:27

    I prefer the short form for print i.e. 'p' to print the frame in lldb. For e.g.

    p (CGRect)[view frame]
    
    0 讨论(0)
  • 2021-02-02 08:28

    Sometimes they are just out of scope by the time you get there.

    Print them to the console:

    NSLog('Frame: %d, %d, %d, %d', frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
    
    0 讨论(0)
提交回复
热议问题