Alex
Alex

Reputation: 5210

Setting a view's bounds changes the coordinates of the frame, WHY?

Why setting the bounds property of a UIView messes up it's frame's coordinates? For example:

self.view.frame = CGRectMake(10, 10, 200, 200);

CGRect b = CGRectMake(0, 0, 399, 323);

self.view.bounds = b;

I would expect the view's frame to be (10, 10, 399, 323) but instead the coordinates get some weird values like (-89.5 -51.5; 399 323).

Thanks!

Upvotes: 1

Views: 206

Answers (1)

jrturton
jrturton

Reputation: 119242

From the UIView class reference:

Changing the bounds size grows or shrinks the view relative to its center point.

So it is keeping the center point in the same place, which means the origin of the frame has to adjust.

If you want to resize the view but keep the origin in the same place, set the frame instead of the bounds.

Upvotes: 3

Related Questions