如何在选项卡栏中启用横向方向 +导航控制器应用程序?

发布于 2024-12-12 08:40:04 字数 1778 浏览 0 评论 0原文

我正在以编程方式创建一个基于选项卡栏的应用程序。在 application:didFinishLaunchingWithOptions (应用程序委托)方法中,我放置了:

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 ,最后一个解决方案可能会导致我的应用程序被 Apple 拒绝。所以我有点困惑到底该怎么做......

提前感谢您的帮助!

史蒂芬

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只有一腔孤勇 2024-12-19 08:40:04

它非常简单,你只需要

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

为你的每一个 ViewController 制作 :- 。

Its very simple you just have to make :-

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

for your each and every ViewController.

じ违心 2024-12-19 08:40:04

我已经使用过你提到的两个选项。

  1. 使 shouldAutorotateToInterfaceOrientation 方法在每个实例化/子类化视图控制器中返回 YES:为此,您需要确保每个视图控制器都有其 shouldAutorotateToInterfaceOrientation 方法返回 YES。一种选择是 CMD+Shift+F 在整个项目中搜索“: UIViewController”,这将显示继承自 UIViewController 的所有头文件的列表,因此在与此对应的每个实现文件中将 shouldAutorotateToInterfaceOrientation 设置为 YES标头。 (这是因为有时您可能包含了第三方代码,该代码具有一些从 UIViewController 继承的类,并且您省略了将 shouldAutorotateToInterfaceOrientation 设置为 YES)

  2. 子类 TabBarController:Apple 文档说 “这个类不是旨在用于子类化。”所以最好避免这个选项,我已经使用过并且它有效,但你总是有被苹果拒绝的可能性。 (也许不是第一次,但在任何升级中)

无论如何,我认为苹果不鼓励标签栏应用程序以横向模式显示,因为标签栏占用了屏幕上的大量空间。因此,最好考虑应用程序的架构,看看是否真的需要 tabbarcontroller,或者创建自己的 tabbarcontroller 控件,例如 iPhone 上的 Twitter 应用程序。这样,您可以在横向模式下降低选项卡栏的高度。

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.

任性一次 2024-12-19 08:40:04

除了在每个子视图控制器中启用旋转(如果您在 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;
}
    }`

UPDATE:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文