[英]Overall size of UIView when clipsToBounds = false
I have a UIView *view
with its view.clipsToBounds = false
. 我有一个UIView *view
及其view.clipsToBounds = false
。 I have added subviews to it whose frames extend beyond the visible bounds of the view
. 我向其添加了子视图,这些子视图的框架超出了view
的可见范围。
My question now is how to get the overall size of the view
, including the extended subviews? 我现在的问题是如何获取view
的整体大小,包括扩展子视图?
I am not able to understand why you want size of view including its subviews, but you can get it by looping through all subviews and applying simple calculations as following: 我无法理解为什么要使用包括子视图在内的视图大小,但是可以通过遍历所有子视图并应用以下简单计算来获得视图的大小:
float x = 0, y = 0, endX = 0, endY = 0;
for (UIView *vw in yourview.subviews)
{
CGRect rct = vw.frame;
if(rct.origin.x < x)
x = rct.origin.x;
if(rct.origin.y < y)
y = rct.origin.y;
if(rct.size.width+rct.origin.x > endX)
endX = rct.size.width + rct.origin.x;
if(rct.size.height + rct.origin.y > endY)
endY = rct.size.height + rct.origin.y;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.