Need a sort of a reverse CATransform3d

733 views Asked by At

I have two views (one is inside the another one).

The superview is "fullscreen" (it means it has frame == screenBounds and layer.transform = CATransform3DIdentity). So it looks like a rect.

The subview has the same frame but also has a defined transform which contains translation, rotation, scale and perspective. So it looks like a trapezium.

Additionally in my case the parent and the child frames don't intersect. So the parent view looks like a rect and the child one looks like a trapezium.

Which one complex transform should I apply to these both views to make the subview "fullscreen"? (after this transform the parent view will become a trapezium vice versa)

If it would be more clear for you I mean this transform:

http://www.youtube.com/watch?v=bjPQG43c_pE&t=1m00s

It occurs when you select one from safari pages 3D list.

1

There are 1 answers

5
lead_the_zeppelin On BEST ANSWER

Assuming your transform matrix of your inner view only contains affine transformations(i.e translate, rotate, scale, reflect, shear) all you need to do is invert your inner view's transformation matrix to transform it to the bounds of the outerview, assuming its frame is the same as the outerview's.

CATransform3D innerViewTransform = innerView.layer.transform;
outerView.layer.transform = CATransform3DInvert(innerViewTransform);

Note: transform is applied around the -anchorPoint property. FYI.