19

我想跟踪什么时候改变 self.view 的大小。正确的格式是什么?

(lldb) po self.view
(UIView *) $1 = 0x0a8aba20 <UIView: 0xa8aba20; frame = (0 0; 480 864); autoresize = W+TM+BM; layer = <CALayer: 0xa8aba50>>
(lldb) watch set variable self.view.frame.size.width
error: "self" is a pointer and . was used to attempt to access "view". Did you mean "self->view.frame.size.width"?
(lldb) watch set variable self->view
error: "view" is not a member of "(PlayViewController *) self"
(lldb) watch set variable self->view.frame.size.width
error: "view" is not a member of "(PlayViewController *) self"

我已经尝试过文档和其他 lldb 观察点问题,但找不到针对此特定案例的任何内容。

谢谢你的帮助。

4

2 回答 2

74

视图控制器从它的_view实例变量中引用它的视图。

视图不直接存储其框架。它只是返回其层的“框架”。

视图从其_layer实例变量中引用其层。

该图层也不存储帧。bounds它根据、positionanchorPoint和计算其框架transform。大小是 的一部分bounds

该层不直接将其边界存储在实例变量中。相反,它的layer实例变量引用了一个私有 C++ 类的实例,CA::Layer. 此类的成员布局未记录。

换句话说,你可以去self->_view->_layer->layerCA::Layer实例,但是你被卡住了,因为你不知道在哪里CA::Layer找到边界。

因此,尝试使用观察点来检测视图大小的变化是相当困难的。

在 .上放置断点更容易-[CALayer setBounds:]

在模拟器上

切记在断点条件中使用层地址,而不是视图地址。

(lldb) po self.view
(UIView *) $1 = 0x0a034690 <UIView: 0xa034690; frame = (0 20; 768 1004); autoresize = W+H; layer = <CALayer: 0xa034780>>
(lldb) break set -F '-[CALayer setBounds:]' -c '((int*)$esp)[1] == 0xa034780'
Breakpoint created: 2: name = '-[CALayer setBounds:]', locations = 1, resolved = 1

当断点被命中时,CALayer实例被 引用((int *)$esp)[1],新的边界是*(CGRect *)($esp+12)

(lldb) po ((int*)$esp)[1]
(int) $8 = 167987072 <CALayer:0xa034780; position = CGPoint (384 480); bounds = CGRect (0 0; 768 1004); delegate = <UIView: 0xa034690; frame = (0 -22; 768 1004); autoresize = W+H; layer = <CALayer: 0xa034780>>; sublayers = (<CALayer: 0xa033010>); backgroundColor = <CGColor 0xa034960> [<CGColorSpace 0xa02b3b0> (kCGColorSpaceDeviceRGB)] ( 1 1 1 1 )>
(lldb) p *(CGRect*)($esp+12)
(CGRect) $9 = origin=(x=0, y=0) size=(width=768, height=960)
(lldb) finish
(lldb) po 0xa034780
(int) $10 = 167987072 <CALayer:0xa034780; position = CGPoint (384 480); bounds = CGRect (0 0; 768 960); delegate = <UIView: 0xa034690; frame = (0 0; 768 960); autoresize = W+H; layer = <CALayer: 0xa034780>>; sublayers = (<CALayer: 0xa033010>); backgroundColor = <CGColor 0xa034960> [<CGColorSpace 0xa02b3b0> (kCGColorSpaceDeviceRGB)] ( 1 1 1 1 )>

在设备上

切记在断点条件中使用层地址,而不是视图地址。

(lldb) po self.view
(UIView *) $0 = 0x1f031a10 <UIView: 0x1f031a10; frame = (0 20; 768 1004); autoresize = W+H; layer = <CALayer: 0x1f031b00>>
(lldb) break set -F '-[CALayer setBounds:]' -c '$r0 == 0x1f031b00'
Breakpoint created: 2: name = '-[CALayer setBounds:]', locations = 1, resolved = 1

当断点被命中时,CALayer实例被 引用$r0,新的 X 原点在$r2,新的 Y 原点在$r3,新的大小是*(CGSize *)$sp

(lldb) po $r0
(unsigned int) $7 = 520297216 <CALayer:0x1f031b00; position = CGPoint (384 480); bounds = CGRect (0 0; 768 1004); delegate = <UIView: 0x1f031a10; frame = (0 -22; 768 1004); autoresize = W+H; layer = <CALayer: 0x1f031b00>>; sublayers = (<CALayer: 0x1f030840>); backgroundColor = <CGColor 0x1f031ce0> [<CGColorSpace 0x1e530ad0> (kCGColorSpaceDeviceRGB)] ( 1 1 1 1 )>
(lldb) p/f $r2
(unsigned int) $14 = 0
(lldb) p/f $r3
(unsigned int) $15 = 0
(lldb) p *(CGSize *)$sp
(CGSize) $16 = (width=768, height=960)
(lldb) finish
(lldb) po 0x1f031b00
(int) $17 = 520297216 <CALayer:0x1f031b00; position = CGPoint (384 480); bounds = CGRect (0 0; 768 960); delegate = <UIView: 0x1f031a10; frame = (0 0; 768 960); autoresize = W+H; layer = <CALayer: 0x1f031b00>>; sublayers = (<CALayer: 0x1f030840>); backgroundColor = <CGColor 0x1f031ce0> [<CGColorSpace 0x1e530ad0> (kCGColorSpaceDeviceRGB)] ( 1 1 1 1 )>
于 2012-12-20T20:52:11.147 回答
4

在 64 位模拟器上,break 命令应该是:

break set -F '-[CALayer setBounds:]' -c '$rdi == 0x...'
于 2016-04-21T06:20:03.943 回答