ios代码切换横竖屏

来源:互联网 发布:数据库审计功能 编辑:程序博客网 时间:2024/04/30 02:45

在想要切换的ViewController类中添加以下三个方法


1. 竖屏

-(NSUInteger)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;

}


- (BOOL)shouldAutorotate

{

    return NO;

}


-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

    return UIInterfaceOrientationPortrait;

}



  1. 横屏


- (BOOL)shouldAutorotate

{

    return NO;

}


-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

    return UIInterfaceOrientationLandscapeRight;

}


-(NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskLandscapeRight;

}


但是值得一提的是:界面之间的跳转应当是模式跳转,否则设置不会达到切换效果,如果通过导航栏进行跳转,push操作是延续上一个的横竖屏状态


0 0
原创粉丝点击