0

I'm programmatically creating a tab bar based app. In the application:didFinishLaunchingWithOptions (app delegate) method I've put:

self.tabBarController = [[[UITabBarController alloc] init] autorelease];

SearchViewController *search_vc = [[[SearchViewController alloc] init] autorelease];
SearchBookmarksViewController *search_bookmarks_vc = [[[SearchBookmarksViewController alloc] init] autorelease];
ItemsBookmarksViewController *items_bookmarks_vc = [[[ItemsBookmarksViewController alloc] init] autorelease];
AboutUsViewController *aboutus_vc = [[[AboutUsViewController alloc] init] autorelease];

UINavigationController *search_nav = [[[UINavigationController alloc] initWithRootViewController:search_vc] autorelease];
UINavigationController *search_bookmarks_nav = [[[UINavigationController alloc] initWithRootViewController:search_bookmarks_vc] autorelease];
UINavigationController *items_bookmarks_nav = [[[UINavigationController alloc] initWithRootViewController:items_bookmarks_vc] autorelease];
UINavigationController *aboutus_nav = [[[UINavigationController alloc] initWithRootViewController:aboutus_vc] autorelease];

NSArray vc_stack = [NSArray arrayWithObjects:search_nav,search_bookmarks_nav,items_bookmarks_nav,aboutus_vc,nil];

tabBarController.viewControllers = vc_stack;

[self.window addSubview:tabBarController.view];

SearchViewController is basically a search form showing results in a UItableView with rows which when selected show details about the chosen row. User can also press a "View Photos" button that push a view controller with a UIImageView to show some photos.

Now when working on the photo view I had to handle landscape orientation which seems not working easily in tab bar applications. Can you help about what to do exactly to allow this photo view controllers to handle landscape orientation ?

I've been told to make shouldAutorotateToInterfaceOrientation method to return YES in every view controller thus making any view to allow landscape orientation OR to subclass TabBarController and this last solution could cause my app to be rejected by Apple. So I'm a bit confuse about what to do exactly...

Thx in advance for your help!

Stephane

Stephane
  • 4,978
  • 9
  • 51
  • 86

3 Answers3

3

Its very simple you just have to make :-

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

for your each and every ViewController.

mAc
  • 2,434
  • 2
  • 22
  • 39
2

I've used both of the options you mention.

  1. make shouldAutorotateToInterfaceOrientation method to return YES in every instanced/subclassed view controller: For this to work you need to make sure that every single view controller has its shouldAutorotateToInterfaceOrientation method to return YES. One option is to CMD+Shift+F to search in the whole project for ": UIViewController", this will show you a list of all the headers files that are inheriting from UIViewController, so set shouldAutorotateToInterfaceOrientation to YES in every implementation file corresponding to this headers. (This because sometimes you may've included a third party code that has some classes that inherits from UIViewController and that you omit to set shouldAutorotateToInterfaceOrientation to YES there)

  2. subclass TabBarController: Apple documentation says that "This class is not intended for subclassing." so it would be better to avoid this option, I have used and it works, but you will always has the possibility of been rejected by Apple. (Maybe not the first time, but on any upgrade)

Anyway, I think Apple doesn't encourage tabbar applications to be displayed in landscape mode because tab bar took a lot of the space on the screen. So it would be better to consider the architecture of your application to see if a tabbarcontroller is really needed or create your own tabbarcontroller control like Twitter app on iPhone. This way you can reduce the height of the tab bar when in lanscape.

Paul N
  • 1,901
  • 1
  • 22
  • 32
1

In addition to enabling rotation in each of the subview controllers (which is enabled by default if you're developing in ios5), if you want to take over the whole screen do something like:

UIInterfaceOrientation toOrientation = self.interfaceOrientation;

if (self.tabBarController.view.subviews.count >= 2 )
    {
UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0];
UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];


if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) {
    transView.frame = CGRectMake(0, 0, 568, 320);
    self.portraitView.hidden = YES;
    self.landscapeView.hidden = NO;
    tabBar.hidden = TRUE;
    self.wantsFullScreenLayout = YES;
}
else
{
    //Designing to accomodate the largest possible screen on an iPhone. The structs and springs should be setup so that the view will remain consistent from portrait to landscape and back to portrait.
    transView.frame = CGRectMake(0, 0, 320, 568);
    tabBar.hidden = FALSE;
    self.portraitView.hidden = NO;
    self.landscapeView.hidden = YES;
    self.wantsFullScreenLayout = NO;
}
    }`

UPDATE:

https://stackoverflow.com/a/13523577/1807026

Community
  • 1
  • 1
sur
  • 51
  • 4