rotate inner rect so it reflects rotation of container rect

86 views Asked by At

I have a container view (blue box) and a subview (green box). I like to rotate the green box so that it reflects the rotation and of the container box.

i rotate the blue box with

CGAffineTransform at;
at = CGAffineTransformMakeRotation(M_PI * 90 / 180.0);
view.frame = CGRectApplyAffineTransform(view.frame, at);
at = CGAffineTransformMakeTranslation(-view.frame.origin.x, -view.frame.origin.y);
view.frame = CGRectApplyAffineTransform(view.frame, at);

what works as expected.

now if i do the same with the green box it will have an origin of 0,0 that's not what i want. so how do i calculate the right origin of the green box? (i tried some things like setting the center of the green box before i rotate, but then realized i really suck at math with matrices..)

enter image description here

Frames:

green box: {100,100},{200,100}

blue box: {0,0}{500,300}


enter image description here

Frames:

green box: {100,200}{100,200}

blue box: {0,0}{300,500}

0

There are 0 answers