views:

684

answers:

2

Okay, this seems like it should be relatively simple, but I've been Googling for the better part of an hour, and can't seem to find what I need.

I have a view controller that has a few different parts: a background view, a header view, and a few buttons. Now, I want the header and buttons to autorotate properly (they do, when I return YES from shouldAutorotateToInterfaceOrientation:), but under no circumstances should the background view rotate. Is there a proper way to do this?

A: 

I don't know about a 'proper' way, but a work-around is to create the background vie image in both orientations and just change the background view. Good question though - will be interested to see what people come up with as a solution.

Jack
+1  A: 

There is another work around that I've thought about...

You could use the:

bgView.transform = CGAffineTransformMakeRotate(angle);

You should calculate the angle according to the orientation (it could be M_PI/2, M_PI or 3*M_PI/2)...

You can use this function inside - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration and also wrap it with an animation that will animate for the exact duration as the screen orientation animation:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    // Decide what will be the angle...

    // Make the animation
    [UIView beginAnimations:@"orientationChange" context:nil];
    [UIView setAnimationDuration: duration];
    bgView.transform = CGAffineTransformMakeRotate(angle);
    [UIView commitAnimations];
}

Notice that view's size might be changed because of the top bar...

Notice also that I've never tried it myself...

Michael Kessler