繁体   English   中英

在旋转和调整大小时如何防止子视图脱离父视图

[英]How to prevent subview go out of superview while rotating and resizing

我将旋转并调整视图(UIImageView)的大小,以使其不会超出supverview的范围。 所以我写了以下内容。

    //rotating and resizing process

    //testing subview is in superview
    CGRect rect = subview.bounds;
    CGRect converted_rect = [subview convertRect:rect toView:subview.superview];
    if(!CGRectContainsRect(subview.superview.frame, converted_rect))
    { 
        //restore proccess
    }

但是我的代码无法防止超出超级视图区域。

如果使用情节提要,请在超级视图的属性检查器中选中“剪辑子视图”框。 如果不是,则UIView具有一个名为clipToBounds的属性,您可以将其设置为YES。 两者都做同样的事情,根据您的项目选择使用情节提要还是编程方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM