TabBar Won't Rotate

Discussion in 'iOS Programming' started by RexInTheCity, Feb 26, 2009.

  1. macrumors newbie

    Joined:
    Jun 9, 2008
    #1
  2. macrumors member

    chbeer

    Joined:
    Sep 22, 2008
    Location:
    Berlin
    #2
    Are you sure your app was realy rotated? maybe add an image or something to see, if the content of the view realy get's rotated.

    My idea would be that you prevent your view from getting rotated. (there is a method for that, I can't remember the name and don't have access to the documentation).
     
  3. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    Sounds like I may need to do a follow-up tutorial... :D
     
  4. thread starter macrumors newbie

    Joined:
    Jun 9, 2008
    #4
    chbeer, you are right about the app not rotating at all.

    This is the only code I have done so far.

    Code:
    #import <UIKit/UIKit.h>
    
    @class ViewController;
    
    @interface AppDelegate : NSObject <UIApplicationDelegate> {
        IBOutlet UIWindow *window;
    	IBOutlet UITabBarController *rootController;
    }
    
    @property (nonatomic, retain) UIWindow *window;
    @property (nonatomic, retain) UITabBarController *rootController;
    
    @end
    Code:
    #import "AppDelegate.h"
    
    @implementation AppDelegate
    
    @synthesize window;
    @synthesize rootController;
    
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
    	[window addSubview:rootController.view];
    	[window makeKeyAndVisible];
    	
    	[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
    }
    
    
    - (void)dealloc {
    	[rootController release];
        [window release];
    	[super dealloc];
    }
    
    @end
    Code:
    #import "ViewController.h"
    
    
    @implementation ViewController
    
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
        // Release anything that's not essential, such as cached data
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    @end
    
     
  5. LTX
    macrumors regular

    LTX

    Joined:
    Dec 25, 2008
    Location:
    Vancouver, BC, Canada
    #5
    I am brand new to iPhone programming, but I've done a few apps from my book, so I may know how to fix it. From what I can tell, it looks like you aren't supporting the landscape left orientation, as in the following code:

    Code:
    @implementation ViewController
    
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    
    Try changing the last line to the following, or simply rotating the simulator the other way:

    Code:
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    
    Or I could be completely wrong.

    If that doesn't work, I'll be back in a bit, and I'll see what the book had to say about the rotating view app.
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Yeah, RexInTheCity, if you didn't change shouldAutorotateToInterfaceOrientation:, you haven't followed my entire tutorial. :)

    EDIT: OK, Tab Bar apps are trickier. They doesn't seem to respond to the techniques from my tutorial. I'm still looking into it...
     
  7. thread starter macrumors newbie

    Joined:
    Jun 9, 2008
    #7
    Adding left doesn't change anything and I only want it on LandscapeRight anyways.
     
  8. thread starter macrumors newbie

    Joined:
    Jun 9, 2008
    #8
    Dejo, I don't suppose you've found anything? I still haven't gotten anywhere
     
  9. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    All I found was this: Auto-rotating Tab Bars on the iPhone

    Haven't had a chance to check it out yet.
     
  10. macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #10
    For what it's worth, I made a Custom Tab Bar Controller class (CustomTabBarController), over-rode shouldAutorotateToInterfaceOrientation for this class, and it worked.

    The documentation says that Tab Bar Controller is not meant to be subclassed; so I guess it's not entirely Kosher.
     
  11. thread starter macrumors newbie

    Joined:
    Jun 9, 2008
    #11
    Thanks Bruin, it worked perfectly.

    Does anyone know of any side effects of subclassing a tab bar controller since Apple doesn't suggest it?
     
  12. macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #12
    Goons. Hired goons. :p
     

Share This Page