Frame vs Bounds in iOS

Frame origin = (40, 60) // That is, x=40 and y=60 width = 80 height = 130 Bounds origin = (0, 0) width = 80 height = 130So you can see that changing the x-y coordinates of the frame moves it in the parent view..But the content of the view itself still looks exactly the same..The bounds have no idea that anything is different.Up to now the width and height of both the frame and the bounds have been exactly the same..That isn’t always true, though..Look what happens if we rotate the view 20 degrees clockwise..(Rotation is done using transforms. See the the documentation and these view and layer examples for more information.)Frame origin = (20, 52) // These are just rough estimates..width = 118 height = 187 Bounds origin = (0, 0) width = 80 height = 130You can see that the bounds are still the same..They still don’t know anything has happened!.The frame values have all changed, though.Now it is a little easier to see the difference between frame and bounds, isn’t it?.The article You Probably Don’t Understand frames and bounds defines a view frame as…the smallest bounding box of that view with respect to it’s parentscoordinate system, including any transformations applied to that view.It is important to note that if you transform a view, then the frame becomes undefined..So actually, the yellow frame that I drew around the rotated green bounds in the image above never actually exists..That means if you rotate, scale or do some other transformation then you shouldn’t use the frame values any more.. More details

Leave a Reply