开发者

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

开发者 https://www.devze.com 2023-01-10 21:56 出处:网络
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?

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 the lack of response. Just to be clear开发者_StackOverflow中文版, what I am looking for is a way to see the frame without adding in extra debugging code.

Also, if the answer is "no you can't do it", bounty will go to the best explanation of why you can see some class members but not others.


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>>


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.


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]


NSLog(@"My view frame: %@", NSStringFromCGRect(myView.frame));


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

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

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.


po [[[[UIApplication sharedApplication]windows] objectAtIndex:0] recursiveDescription]

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


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


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>>


Found an answer for lldb. For example, this works

(lldb) print (CGRect)[((UIView *)[[[self backIV] subviews] objectAtIndex:1]) frame]


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

p (CGRect)[view frame]


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);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号