gpt4 book ai didi

ios - preferredInterfaceOrientationForPresentation 没有被调用

转载 作者:行者123 更新时间:2023-11-29 13:07:07 29 4
gpt4 key购买 nike

我有一个场景,其中我有一个带有 5 个选项卡的 UITabbarController。每个选项卡都包含一个 UINavigationController。

现在在 UINavigationController rootViewController 之一中,当我选择一个选项时,将推送另一个 View Controller 。现在我希望另一个 View Controller 只是风景。

以下是我的 UITabBarController 和 UINavigationController 类的 Orientation 代码

@implementation UITabBarController (rotation)

-(BOOL)shouldAutorotate
{
if ([self.selectedViewController respondsToSelector:@selector(shouldAutorotate)]) {
return [self.selectedViewController shouldAutorotate];
}
else {
return YES;
}
}

- (NSUInteger)supportedInterfaceOrientations
{
if ([self.selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
return [self.selectedViewController supportedInterfaceOrientations];
}
else if(DEVICE_IS_IPAD)
return UIInterfaceOrientationMaskAll;
else
return UIInterfaceOrientationMaskPortrait;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if ([self.selectedViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
return 0;
}

@end

@implementation UINavigationController (AutoRotationForwarding)

-(BOOL)shouldAutorotate
{
if ([self.topViewController respondsToSelector:@selector(shouldAutorotate)]) {
return [self.topViewController shouldAutorotate];
}
else {
return YES;
}
}

-(NSUInteger) supportedInterfaceOrientations {
if([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)])
{
return [self.topViewController supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if ([self.topViewController respondsToSelector:@selector(supportedInterfaceOrientations)]) {
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
return UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationPortraitUpsideDown;
}
@end

我只想成为 Landscape 的 ViewController 的代码是:

-(BOOL)shouldAutorotate
{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
if(DEVICE_IS_IPAD)
return UIInterfaceOrientationMaskLandscape;
else
return UIInterfaceOrientationMaskPortrait;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}

主要问题是 preferredInterfaceOrientationForPresentation 根本没有为 UITabbarController 或 UINavigationBarController 甚至我想显示的 View Controller 调用。

你能告诉我我做错了什么吗?

谢谢。

最佳答案

您可能忘记将supportedInterfaceOrientationsForWindow 添加到您的 AppDelegate 中?

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}

关于ios - preferredInterfaceOrientationForPresentation 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18330158/

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