Get size of UIView after applying CGAffineTransform

后端 未结 6 649
[愿得一人]
[愿得一人] 2020-12-23 15:26

I was surprised not to find an answer to this question, maybe is something very simple I somehow overlook :

How to get the real size of an UIView after I apply a CG

6条回答
  •  眼角桃花
    2020-12-23 15:44

    [myView frame] returns the frame of the view as seen by the parent, for layout and relative sizes. [myView bounds] returns the bounds of the view as seen by itself, for drawing. If you have transforms applied to multiple views, you can use convertRect: to or from a view.

    Edit:

    Maybe something like this.

    CGRect rect = [view bounds];
    CGPathRef path = CGPathCreateMutable();
    rect.origin = CGPointZero;
    CGPathAddRect( rect , [view transform] );
    rect = CGPathGetBoundingBox( path );
    CGPathRelease( path );
    

    The use [view center] to find the position in the superview.

提交回复
热议问题