views:

157

answers:

1

How can I rotate my base view and still make sure that its subviews are still in their correct locations?

--------                            
|X     |   After 90 degree rotate and stretch
|      |   this should remain the same
|      |
|     Y|
--------

I presume I need to rotate 90 degrees and stretch according to window ratio and perform the opposite on the subview?

The following does not work...

- (void) performTransformation:(UIView*)view isBase:(BOOL)isBase
{
    if(isBase) {
        [view.layer setAffineTransform:CGAffineTransformConcat(
            CGAffineTransformMakeRotation(M_PI * 0.5),
            CGAffineTransformMakeScale(-(3.0/4.0), (4.0/3.0)))];
    } else {
        [view.layer setAffineTransform:CGAffineTransformConcat(
            CGAffineTransformMakeScale(-(4.0/3.0), (3.0/4.0)),
            CGAffineTransformMakeRotation(-M_PI * 0.5))];
}
A: 

Are you rotating in response to the device’s orientation changing? If so, you can just use UIViewController’s -shouldAutorotateToInterfaceOrientation: method to rotate the view.

To do what you're describing, you can set the individual UIViews’ autoresizingMask property. In your example, you'd do the following:

[viewX setAutoresizingMask:(UIViewFlexibleRightMargin |
                            UIViewFlexibleBottomMargin )];

[viewY setAutoresizingMask:(UIViewFlexibleTopMargin |
                            UIViewFlexibleLeftMargin )];

That code will set the first view (which I’ve called viewX) to stay with the top-left corner, and the second view with the bottom-right.

Jeff Kelley
No, I am resizing the base in order to rotate the effect of a UIView animation.
LK
Well, as long as what you're rotating and transforming is the superview to those views, setting the autoresize mask should work.
Jeff Kelley