简体   繁体   English

clipsToBounds = false时,UIView的总体大小

[英]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.

相关问题 阴影 UIview 和 clipsToBounds - Shadow UIview and clipsToBounds UIView clipsToBounds 不起作用 - UIView clipsToBounds doesn't work 根据 UIView 和 UITextView 的整体大小动态调整 UIScrollView contentSize - Dynamically adjust UIScrollView contentSize depending on the overall size of a UIView and UITextView 将 UIView.layer.clipsToBounds = true 与 CABasicAnimation 结合使用时,并非所有像素都被裁剪 - Not all pixels clipped when using UIView.layer.clipsToBounds = true in conjunction with CABasicAnimation 在带有 clipsToBounds 的 UIView 中添加为子视图的 UIImageView 不起作用 - UIImageView added as subview in an UIView with clipsToBounds is not working Swift 4 - UIView 框架显示错误尺寸 - Swift 4 - UIView frame shows false size 如何在故事板设计器和整体运行时视图中限制UIView的大小? - How do I limit the size of a UIView in a storyboard designer and the runtime view overall? UIView的clipsToBounds和CALayer的maskToBounds之间的关系如何? - How is the relation between UIView's clipsToBounds and CALayer's masksToBounds? KVO 检查目标 c 中 UIView 中所有子视图的 clipsToBounds 的变化 - KVO check for change of clipsToBounds of all subviews in an UIView in objective c 设置没有 clipsToBounds 的圆角半径仅适用于 UIView 类型? - Setting corner radius without clipsToBounds works only for UIView type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM