简体   繁体   中英

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

I'am going to rotate and resize a view(UIImageView) so that it doesn't go out of supverview. So I wrote following.

    //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
    }

But my code can't prevent going out of superview area.

If you're using storyboard, check the box "clip subviews" in the superview's attribute inspector. If not, UIView has a property called clipToBounds that you can set to YES. Both do the same thing, choose whether to use the storyboard or programmatic method based on your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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