gpt4 book ai didi

ios preferredInterfaceOrientationForPresentation 未调用

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

我只是创建了一个新的单 View 应用程序,并在 ViewController.m 文件中编写了三个函数。

-(BOOL)shouldAutorotate
{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}

第一个问题

我希望模拟器旋转我的 View ,但 View 方向是纵向的。而且我发现 ViewController 中没有调用第三个函数。为什么?

第二个问题

我读了一些博客,他们说如果 shouldAutorotate return NO,func supportedInterfaceOrientations 将不会被调用,但在我的测试中,这个 func 被调用了几次,为什么?

最佳答案

您必须使用 UINavigationController 子类(不确定您在项目中使用导航...)并在子类中实现这些方法。不要忘记将您的子类设置为 View Controller 导航 Controller
导航 Controller 子类的示例:

// add this in your CustomNavigationController.h file

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController <UINavigationControllerDelegate>

@end

// add this in your : CustomNavigationController.m file

#import "CustomNavigationController.h"

@interface CustomNavigationController ()

@end

@implementation CustomNavigationController

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

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [self.visibleViewController preferredInterfaceOrientationForPresentation];
}

@end

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

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