tags:

views:

4778

answers:

6

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...

+1  A: 

You can hide the status bar by calling

setStatusBarHidden:(BOOL)

on a UIApplication reference, like so.

- (void)applicationDidFinishLaunching:(UIApplication *)application {

[application setStatusBarHidden:YES];

}

To get rid of the tabbar you can make a referencing outlet in Interface builder to your code and call

[myUITabBar removeFromSuperview];

That might work, although I haven't tested it, as for the other questions, i'm not 100%, having not tackled the problems before.

Gcoop
+1  A: 

Ok, this is as far I put this to work:

- (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));
     }
    }
}

Now, in the AppDelegate:

- (void) didRotate:(NSNotification *)notification
{   
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    [UIView beginAnimations:nil context:NULL];  

    if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
    {
     [tabBarController.view setAlpha:0.0];
     [tabBarController.view removeFromSuperview];

     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; 
    } else {
     [tabBarController.view setAlpha:1.0];
     [[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];  
    }
    [UIView commitAnimations];  
}

But then how set the current view and how restore the tabbar?

mamcx
+1  A: 

When I look at the iPod app, it seems to me that the TabBarController view is not replaced or modified in any way. I think there is just a fade transition between the tabbarcontroller view and the coverflow view.

If I were you, I would try (not sure if this might work) with a coverflow controller, with its view displayed on top of the tabBarController's view. If would prevent the tabBarController from autorotating its view, but at that moment I would fade out its view and fade in the coverflow view, which would be landscape only.

I don't know if the statusBar would have a proper behavior, and I let a lot of details for you to sort out, but in any case I think it would be a nice idea to have two separate controllers, one showed in landscape, the other (the tabBar) in portrait.

Hope that will help you.

Unfalkster
+1  A: 

There seem to be a fair number of coders who want to have a tab bar item take them to a landscape view full screen (no status bar, no tab bar) and then come back.

I've posted an inquiry about whether this is indeed possible on the Apple developers forum, but have not yet had a reply.

Why is this hard? (sorry, a newbie question? It seems like some rather obvious things shouldn't be hard) Nobody I have found yet online has a clear answer to this.

Mel Malinowski
+3  A: 

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.

Shel