未调用演示文稿的ios preferredInterfaceOrientationForPresentation

未调用演示文稿的ios preferredInterfaceOrientationForPresentation,ios,objective-c,Ios,Objective C,我只是创建了一个新的单视图应用程序,并在ViewController.m文件中编写了三个func -(BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape; } -(UIInterfaceOrien

我只是创建了一个新的单视图应用程序,并在ViewController.m文件中编写了三个func

-(BOOL)shouldAutorotate
{
    return YES;
}

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

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}
第一个问题

我希望模拟器旋转我的视图,但视图方向是纵向的。我发现ViewController中没有调用第三个func。为什么?

第二个问题


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

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

// 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
//将其添加到CustomNavigationController.h文件中
#进口
@接口CustomNavigationController:UINavigationController
@结束
//将其添加到:CustomNavigationController.m文件中
#导入“CustomNavigationController.h”
@接口CustomNavigationController()
@结束
@CustomNavigationController的实现
-(BOOL)应该自动旋转{
return[self.visibleViewController shoulldautorotate];
}
-(整数)支持的接口方向{
返回[self.visibleViewController支持的界面方向];
}
-(UIInterfaceOrientation)首选交互方向进行演示{
返回[self.visibleViewController preferredInterfaceOrientationForPresentation];
}
@结束

没有navigationController,只有一个作为RootViewController的ViewController。您需要一个navigationController:)