Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How rotate view to landscape in a tabbar app

I have a tabbar based app.

I build 2 views, one in portrait and another in landscape mode in the Interface Builder.

Now, I wanna something like the iPod App. I wanna the landscape view to be fullscreen, and hide the tabbar & the status bar.

I make to work the basic of this:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                                duration:(NSTimeInterval)duration { 
    if (self.landscape) {
        if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
        {
            self.view = self.portrait;
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(360));
        }
        else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        {
            self.view = self.landscape;
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
        }
        else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
        {
            self.view = self.landscape;
            self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
        }
        else
        {
            self.view = self.portrait;
            self.view.transform =  CGAffineTransformMakeRotation(degreesToRadian(-180));
        }
    }
}

But all work messy. The landscape view not correctly fill the area and the controls are located in wrong locations, diferent as desingned first.

Also, I still not found a way to hide everything else...

like image 908
mamcx Avatar asked Feb 10 '09 21:02

mamcx


1 Answers

Look at Apple's "AlternateViews" sample code.

The basic idea is that you can detect the physical orientation of the device with notifications, and then activate a new view controller "modally" and have it request the full screen. You disable interface rotation by having shouldAutorotate... return YES only for one orientation, since you are doing all this manually with notifications. When you change the physical orientation, your modal view controller is either presented or dismissed.

like image 76
Shel Avatar answered Oct 02 '22 23:10

Shel