简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM