在工程文件中配置支持横竖屏功(Device Orientation),可以设置设备iPhone或iPad
在AppDelegate.h中添加以下属性
@property (nonatomic, assign) UIInterfaceOrientationMask interfaceOrientation;
3.在AppDelegate.m中实现代理方法:
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
return self.interfaceOrientation;
}
4.在相应viewcontroller中调用appdelegate中interfaceOrientation属性,建议在viewWillAppear中调用,且在自定义的基类viewcontroller中使用,使用子类去重写该方法:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
AppDelegate appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.interfaceOrientation = UIInterfaceOrientationMaskPortrait; // 横屏
}
5.如果需要在某个页面修改横竖屏属性,请重复第4步