2011-10-27 43 views
0

我正在编程创建基于标签栏的应用程序。在应用中:didFinishLaunchingWithOptions(应用程序委托)方法我已经把:如何在选项卡栏中启用横向导航+ NavigationControllers应用程序?

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是基本上表示一个UITableView与当选择关于所选择的行显示详细信息的行结果的搜索表单。用户也可以按下“查看照片”按钮,用UIImageView推动视图控制器显示一些照片。

现在,当处理照片视图时,我不得不处理横向方向,这在标签栏应用程序中似乎不太容易工作。你能帮助我们做些什么来让这张照片视图控制器能够处理横向方位吗?

我被告知要shouldAutorotateToInterfaceOrientation方法在这样每个视图控制器作出任何视图,允许横向返回YES或子类TabBarController,这最后的解决办法可能会导致我的应用程序被苹果拒绝。所以我有点搞不清楚该怎么做...

Thx提前为您提供帮助!

斯特凡

回答

2

我用两个的你提到的选项。

  1. 化妆shouldAutorotateToInterfaceOrientation方法在每个实例化返回YES /子类视图控制器:对于这个工作,你需要确保每一个视图控制器都有shouldAutorotateToInterfaceOrientation方法返回YES。一种选择是让CMD + Shift + F在整个项目中搜索“:UIViewController”,这将向您显示从UIViewController继承的所有头文件的列表,因此在与此相对应的每个实现文件中将shouldAutorotateToInterfaceOrientation设置为YES头。 (这是因为有时你may've包含有一些类,它们的UIViewController继承和省略到shouldAutorotateToInterfaceOrientation设置为YES有没有第三方的代码)

  2. 子TabBarController:苹果文档中说,“这个类是不打算进行子分类“。所以最好避免使用这个选项,我已经使用过它,但是你永远有可能被Apple拒绝。 (也许不是第一次,但在任何升级)

无论如何,我认为苹果不鼓励的TabBar应用程序进行横向显示模式,因为标签栏拍了很多画面上的空间。因此,最好考虑应用程序的体系结构,以查看是否真的需要tabbarcontroller或创建自己的tabbarcontroller控件,如iPhone上的Twitter应用程序。这样,您可以在lanscape中减少标签栏的高度。

+0

它工作正常!谢谢 – Steve

3

它非常简单,你只需要做: -

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

您的每一个视图控制器。

1

除了在每个子视图控制器能够转动(这是在默认情况下,如果你在iOS5中开发支持),如果你想接管整个屏幕做类似:

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; 
} 
    }` 

更新:

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

相关问题