Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app - how to make main window rotate

I have a background image in my main window so that when I flip views, it's not a blank white screen behind, but an image. My problem is that this image doesn't rotate when the device rotates.

Edit: As far as I can tell, Brett was correct when he pointed out that I'd have to rotate the background image manually in this instance. In case it helps anyone else out in the future, here's how I rotated it.

Inside myAppDelegate:

- (void) application:(UIApplication *)application
        willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation
        duration:(NSTimeInterval)duration
{
    if (newStatusBarOrientation == UIInterfaceOrientationPortrait)
        self.bgImage.transform      = CGAffineTransformIdentity;
    else if (newStatusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
        self.bgImage.transform      = CGAffineTransformMakeRotation(-M_PI);
    else if (UIInterfaceOrientationIsLandscape(newStatusBarOrientation))
    {
        float rotate    = ((newStatusBarOrientation == UIInterfaceOrientationLandscapeLeft) ? -1:1) * (M_PI / 2.0);
        self.bgImage.transform      = CGAffineTransformMakeRotation(rotate);
        self.bgImage.transform      = CGAffineTransformTranslate(self.bgImage.transform, 0, -self.bgImage.frame.origin.y);
    }
}
like image 975
story Avatar asked Aug 15 '11 18:08

story


People also ask

How do I rotate my main screen?

Select the Start button, then type settings. Select Settings > System > Display, and choose a screen orientation from the drop-down list next to Display orientation.


1 Answers

I think that UIWindow passes on rotation events to child controllers. The window should contain the root view controller view then pass on the rotation event message to the view controller to manage the rotation.

You should be able to listen for these events in your app delegate and manage the image rotation manually. Otherwise, just add the image as a subview of the root view controller.

like image 83
Brett Avatar answered Sep 28 '22 00:09

Brett