iPhone -- 是否可以在 Xcode 调试器中检查 UIView 的框架?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3435354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iPhone -- is it possible to inspect the frame of a UIView in the Xcode debugger?
提问by William Jockusch
When the debugger is stopped at a breakpoint, I can't find the frame of any of my UIViews in there.
当调试器在断点处停止时,我在那里找不到任何 UIViews 的框架。
Is it possible to do this?
是否有可能做到这一点?
EDIT: starting a bounty due to the lack of response. Just to be clear, 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.
此外,如果答案是“不,你做不到”,赏金将最好地解释为什么你可以看到一些班级成员但看不到其他人。
回答by Hilton Campbell
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:
是的,你可以做到。调试时,在变量检查器中找到感兴趣的 UIView。按住 Control 键单击它并选择“将描述打印到控制台”。例如,我在 UIViewController 的 _view ivar 上执行此操作,控制台中出现以下内容:
Printing description of _view:
<UIView: 0x25b460; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x26b740>>
_view 的打印说明:
<UIView: 0x25b460; 帧 = (0 0; 320 480); 自动调整大小 = W+H; 层 = <CALayer:0x26b740>>
回答by Douglas
If you go to the debugger panel, you can type this in while you are at a breakpoint:
如果您转到调试器面板,您可以在断点处输入以下内容:
(gdb) print (CGRect) [self frame]
= {
origin = {
x = 0,
y = 0
},
size = {
width = 100,
height = 100
}
}
When using the console debuggeryou can press the up arrow key to cycle through previous commands. Pressing return without entering a command repeats the last command.
使用控制台调试器时,您可以按向上箭头键循环浏览以前的命令。在不输入命令的情况下按回车键会重复上一个命令。
回答by Adam
Re-formatting @EPage_Ed's answer because the original was hard-coded for his specific case:
重新格式化@EPage_Ed 的答案,因为原件是针对他的特定情况进行硬编码的:
At the (lldb) prompt, type:
在 (lldb) 提示符下,键入:
print (CGRect)[view frame]
Or, for the bounds:
或者,对于边界:
print (CGRect)[view bounds]
回答by Nishant
NSLog(@"My view frame: %@", NSStringFromCGRect(myView.frame));
回答by Sid
In XCode 5.1.1, you can hover over a variable that is a UIView and you will see the following type of popover:
在 XCode 5.1.1 中,您可以将鼠标悬停在 UIView 变量上,您将看到以下类型的弹出框:
If you click on the 'i' button, the following type of output will be printed in the debugger's console:
如果单击“i”按钮,调试器的控制台中将打印以下类型的输出:
<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.
这是检查 UIView 框架的另一种方法。
回答by Breeno
Interestingly, using the getter method to return the view's frame works:
有趣的是,使用 getter 方法返回视图的框架是有效的:
print (CGRect)[view frame]
This gives the expected result:
这给出了预期的结果:
(CGRect) = 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
回答by Real World
po [[[[UIApplication sharedApplication]windows] objectAtIndex:0] recursiveDescription]
will print out the entire view heirachy but only seems to work in gdb and not llvm
将打印出整个视图 heirachy 但似乎只适用于 gdb 而不是 llvm
回答by C. Lee
In Xcode, go to the console and type:
在 Xcode 中,转到控制台并键入:
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>>
回答by jarora
I prefer the short form for print i.e. 'p' to print the frame in lldb. For e.g.
我更喜欢打印的简短形式,即“p”在 lldb 中打印框架。例如
p (CGRect)[view frame]
回答by EPage_Ed
Found an answer for lldb. For example, this works
找到了 lldb 的答案。例如,这有效
(lldb) print (CGRect)[((UIView *)[[[self backIV] subviews] objectAtIndex:1]) frame]