clipsToBounds = false时UIView的总大小

时间:2016-12-02 05:45:53

标签: ios uiview size

我的UIView *viewview.clipsToBounds = false。我添加了子视图,其框架超出了view的可见范围。

我现在的问题是如何获得view的整体尺寸,包括扩展的子视图?

1 个答案:

答案 0 :(得分:0)

我无法理解您为什么需要包含其子视图的视图大小,但您可以通过循环遍历所有子视图并应用以下简单计算来获取它:

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;

}