Search code examples
iosuiviewuiscrollviewframecatransform3d

Approximate rect after applying CATransform3D?


I applied CATransform3D to a view. How can I find its approximate new frame after it?

I mean I applied a complex transform: rotation, translation, scale and perspective. And I need to find something like approximate minimal rect. I need it because this view is added to UIScrollView (to know the contentSize I need and of course to implement "scrollToItem:")


Solution

  • If you want to get the CGRect that completely contains this transformed view, you can use convertRect:toView:. For example:

    CGRect rect = [viewWithTransforms convertRect:viewWithTransforms.bounds toView:self.view];
    

    For example, the gray view is some transformed UIView, and the black border is the result of convertRect:toView: shown above:

    enter image description here