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

前端 未结 12 560
执念已碎
执念已碎 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:30

    To get a the frame information similar to the debugger as an NSString, use NSStringFromCGRect(someView.frame)

    0 讨论(0)
  • 2021-02-02 08:33
    NSLog(@"My view frame: %@", NSStringFromCGRect(myView.frame));
    
    0 讨论(0)
  • 2021-02-02 08:35

    Yes, you can do it. While debugging, find the UIView of interest in the variable inspector. Control-click on it and select "Print Description to Console". For example, I did this on the _view ivar of a UIViewController and the following appeared in the console:

    Printing description of _view:
    <UIView: 0x25b460; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x26b740>>

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

    Interestingly, using the getter method to return the view's frame works:

    print (CGRect)[view frame]
    

    This gives the expected result:

    (CGRect) $2 = origin=(x=0, y=20) size=(width=320, height=48)
    

    But if you try to use dot notation, which I hear so often referred to as being provided simply for 'syntactic sugar':

    print (CGRect)view.frame
    

    You get the following error:

    error: C-style cast from '<unknown type>' to 'CGRect' is not allowed
    
    0 讨论(0)
  • 2021-02-02 08:40

    If you go to the debugger panel, you can type this in while you are at a breakpoint:

    (gdb) print (CGRect) [self frame]
    $1 = {
      origin = {
        x = 0, 
        y = 0
      }, 
      size = {
        width = 100, 
        height = 100
      }
    }
    

    When using the console debugger you can press the up arrow key to cycle through previous commands. Pressing return without entering a command repeats the last command.

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

    In XCode 5.1.1, you can hover over a variable that is a UIView and you will see the following type of popover:

    enter image description here

    If you click on the 'i' button, the following type of output will be printed in the debugger's console:

    <UIImageView: 0xa49ca90; frame = (0 0; 640 360); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xa46c1c0>>
    

    This is another way of inspecting the frame of a UIView.

    0 讨论(0)
提交回复
热议问题