Anonymous White
Anonymous White

Reputation: 2169

When debugging how do we know the frame of a UIView or how is it stored?

Take a look at the picture below

enter image description here

I am looking for UIView and I cannot find this so called _frame struct.

How internally exactly apple store a UIView frame? And what would be the easiest way to find that out during debugging?

Upvotes: 0

Views: 77

Answers (1)

rob mayoff
rob mayoff

Reputation: 386018

A UIView doesn't store its frame; it just returns its layer's frame.

A CALayer doesn't store its frame either. When you ask a layer for its frame, the layer computes the frame based on the layer's bounds, position, anchorPoint, and transform. (Possibly it caches the computed frame, but if you disassemble the -[CALayer frame] method you will find code for computing it from the other properties.)

And a CALayer doesn't store any of those properties in instance variables. Instead, it has a pointer to a CA::Layer instance, which is a private C++ object. That C++ object stores the layer's properties. The view->_layer->_attr.layer field is the pointer to the private CA::Layer instance.

If you want to see a view's frame in the debugger, you have to send it a message. You can ask it for its description:

po _topBubble

Or you can ask it for its frame:

p (CGRect)[_topBubble frame]

Upvotes: 3

Related Questions