gpt4 book ai didi

objective-c - 如何在标签栏应用程序的 iOS 6 GM 中使旋转正常工作?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:23:30 26 4
gpt4 key购买 nike

旋转在 iOS 5 中工作得很好,现在它根本不起作用。我设置了它,以便当某个 View 打开时在选项卡 1 上我的所有 View 都保持纵向异常,然后用户可以旋转并且它会显示 coverflow 样式的 View 。

我的设置是在运行时在 AppDelegate 中创建我的标签栏。然后我将它设置为主 Root View :

self.window.rootViewController = self.tabBarController;

但是我的所有 View ,在所有选项卡上,现在无论如何都向左或向右旋转。而且我已经尝试添加新代码(来自论坛中的多个示例)但无济于事......我断点了所有内容,并且在我旋转手机时没有调用任何旋转代码。

每个 TabController 中都有一个 NavigationController,然后在其中有我的主视图和我的所有 UI。

关于如何在 iOS 6 中正确旋转的任何想法或指示?非常令人沮丧,因为这是我在发货前需要解决的最后一个问题。

最佳答案

这将使您启动并运行。最终你真的应该子类化这些 UIKit 类而不是使用类别,但不幸的是,这不适用于尚未针对 iOS 6 修复的第三方库。这些类别应该适用于所有内容,而不需要你在其他人的代码中乱搞。

我还没有看到任何不涉及子类化(或编写类别)的UITabBarControllerUINavigationController 问题的解决方案。不过,我希望有一个。

确保在 Prefix.pch 文件的顶部导入三个 .h 文件(如果您选择将它们全部添加到一个文件,则导入一个) .您必须确保尽快加载此代码!

UITabBarController+LegacyRotation.h

#import <UIKit/UIKit.h>

@interface UITabBarController (LegacyRotation)

@end

UITabBarController+LegacyRotation.m

#import "UITabBarController+LegacyRotation.h"

@implementation UITabBarController (LegacyRotation)

- (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}

- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}

@end

UINavigationController+LegacyRotation.h

#import <UIKit/UIKit.h>

@interface UINavigationController (LegacyRotation)

@end

UINavigationController+LegacyRotation.m

#import "UINavigationController+LegacyRotation.h"

@implementation UINavigationController (LegacyRotation)

- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}

- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}

@end

UIViewController+LegacyRotation.h

#import <UIKit/UIKit.h>

@interface UIViewController (LegacyRotation)

@end

UIViewController+LegacyRotation.m

#import "UIViewController+LegacyRotation.h"

@implementation UIViewController (LegacyRotation)

- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger ret = 0;

if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait]) {
ret |= UIInterfaceOrientationMaskPortrait;
}
if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown]) {
ret |= UIInterfaceOrientationMaskPortraitUpsideDown;
}
if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft]) {
ret |= UIInterfaceOrientationMaskLandscapeLeft;
}
if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight]) {
ret |= UIInterfaceOrientationMaskLandscapeRight;
}

return ret;
}

- (BOOL)shouldAutorotate
{
return YES;
}

@end

关于objective-c - 如何在标签栏应用程序的 iOS 6 GM 中使旋转正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12417872/

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