gpt4 book ai didi

iphone - 虽然我有uinavigationcontroller的类别来转发调用,但应该没有调用shouldAutorotate

转载 作者:行者123 更新时间:2023-12-01 19:15:51 24 4
gpt4 key购买 nike

我有点困惑。
我希望我的应用程序完全在我的5个Viewcontrollers中之一旋转。
我为UINavigationcontroller创建了一个Category,实现了在ios 6中旋转所需的方法。

#import "UINavigationController+IOS6Rotation.h"


@implementation UINavigationController (IOS6Rotation)

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

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if (INTERFACE_IS_PAD) {
return UIInterfaceOrientationLandscapeLeft;
}
else{
return UIInterfaceOrientationPortrait;
}
}
@end

我还在所有不应旋转的ViewController中实现了这些方法。
- (BOOL)shouldAutorotate {
return NO;
}

- (BOOL)supportedInterfaceOrientations {
if (INTERFACE_IS_PAD) {
return UIInterfaceOrientationMaskLandscape;
}
else{
return UIInterfaceOrientationMaskPortrait;
}
}

应该旋转的人在shouldAutorotate中返回YES

在启动时,我使用一个额外的Viewcontroller来显示启动画面。这样,SplashScreen将显示为RootViewController。
vc_splash = [[SplashScreenViewController alloc] initWithNibName:@"SplashScreenViewController" bundle:[NSBundle mainBundle]];
[self.window setRootViewController:vc_splash];

DefaultSHKConfigurator *configurator = [[MySHKConfigurator alloc] init];
[SHKConfiguration sharedInstanceWithConfigurator:configurator];
[self.window makeKeyAndVisible];

当我完成数据库的加载后,初始屏幕将替换为主屏幕。
self.viewController = [[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: self.viewController];
[self.window setRootViewController: navControl];

现在的问题是,只有我的Splashscreen调用才应该自动旋转,而其他屏幕则不应该。
有人可以告诉我我是否在这里错过了一些必需品吗?
我以为我已经做了所有必要的工作以使bl **** y自动旋转能够在ios 6中正常工作...

提前谢谢
小牛第1

**更新**
如果您希望iPad在横向模式下启动,请确保在shouldAutoRotate中返回YES,

最佳答案

这对我来说是工作添加supportedInterfaceOrientationsForWindowapplication中的方法delegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
[navigationController shouldAutorotate];
[navigationController preferredInterfaceOrientationForPresentation];
return UIInterfaceOrientationMaskAll;
}

还要在 application delegate中添加它:
@implementation UINavigationController (Rotation_IOS6)

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

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end

关于iphone - 虽然我有uinavigationcontroller的类别来转发调用,但应该没有调用shouldAutorotate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13416349/

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