개발/swift

Swift frame vs bounds

lemonade 2020. 10. 14. 21:38
반응형

Frame VS Bounds


All UIView subclasses have two properties that is frame and bounds. 

They are similar in a way both return a CGRect,  a rectangle containing X and Y position plus width and height.

But they are not the same.

Both frame and bounds is a view’s location and size.


Frame using the parent view’s coordinate system whereas bounds using it’s own coordinate system.

For clarify

If you create a view at X=0, Y=0 with some width and height, frame and bounds are identical.

If you move that view to X=100 or Y=100, frame will change accordingly otherwise bounds not.


If you transform that view like rotating or scaling. Frame will change accordingly otherwise bounds not.

 


You can change either frame or bounds and the other value will update accordingly.  In general, bounds are commonly used when a view has a transform applied to it. Under these circumstances the frame property is undefined.  Modifying the center and bounds are equivalent to modifying the view's position and size respectively.

But as mentioned above, bounds and frame are interlocked. 

Changing one will makes the other update happened

 

So decide what to change is up to you!

Happy coding!

반응형
그리드형

'개발 > swift' 카테고리의 다른 글

Swift codable protocol  (0) 2020.10.17
Swift How to get range of substring?  (0) 2020.10.17
How to get app store version in swift?  (0) 2020.10.13
Swift Random Generator  (0) 2020.10.13
Alamofire 5 Network Interceptor  (0) 2020.10.12