gpt4 book ai didi

iphone - iOS6 中设备旋转时选项卡栏应用程序崩溃

转载 作者:行者123 更新时间:2023-12-03 19:54:22 25 4
gpt4 key购买 nike

这不是一个重复的问题。尚未提供最终的工作解决方案,因此在我们接受答案或找到并提供我们自己的 100% 工作解决方案之前,请不要关闭此问题。谢谢!

================================================== ===================
使用 Xcode 4.5.1,我们有一个带有 5 个选项卡的选项卡栏应用程序。每个选项卡都包含一个 UINavigationController,因此整个应用程序需要以纵向模式查看。有一个异常(exception):“图像库”类型的 View Controller ,我们需要在横向模式下打开并全屏查看。

我们能够在 iOS5 中轻松地在某个特定 ViewController 中使用以下代码来完成此操作:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

但是 shouldAutorotateToInterfaceOrientation 在 iOS6 中已被弃用,并且不再起作用。
因此,为了使其在 iOS6 中正常工作,我们到目前为止已采取以下步骤:
1)创建了UITabBarController的子类(这是我们的rootViewController)
2) 将其 supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation 设置为 UIInterfaceOrientationMaskPortrait (但请注意,我们没有在其中实现 shouldAutorotate 方法)
3) 将项目/目标支持的方向设置为全部

这几乎完美地工作:我们的“图片库”ViewController 确实响应两种横向模式 - 正如它应该的那样 - 但它最初仍然以纵向打开 - 这很糟糕。我们需要它在横向模式下正确打开 - 并且永远无法以纵向模式显示。现在它仍然在做这两件事。

知道为什么这样做 - 或者如何解决它?

最佳答案

我在使用的应用程序中遇到了完全相同的问题,这就是我解决它的方法。

首先,我使用纵向代码创建了一个名为 NonRotatingTabBarControllerUITabBarController 子类

NonRotatingTabBarController.h

#import <UIKit/UIKit.h>

@interface NonRotatingTabBarController : UITabBarController
@end

NonRotatingTabBarController.m

#import "NonRotatingTabBarController.h"

@implementation NonRotatingTabBarController

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

@end

现在,当您创建选项卡栏 Controller 时,它需要是 NonRotatingTabBarController 的实例

self.tabBarController = [[NonRotatingTabBarController alloc] init]; // or whatever initialising code you have but make sure it's of type NonRotatingTabBarController

现在,在唯一需要横向支持的 View Controller 中,您需要重写旋转方法,以便它进行旋转。就我而言,它必须固定为横向

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight);
}

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}

在您的项目/目标设置中,您必须启用对应用程序使用的所有界面方向的支持,否则它将崩溃。让上面的代码负责旋转启用/禁用。

Xcode Project Settings

希望有帮助!

关于iphone - iOS6 中设备旋转时选项卡栏应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13182092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com