iOS9横屏竖屏设置

公司App里面有个需求,即所有界面都是竖屏,且不允许横屏切换,唯独有一个播放视频的界面允许横屏,大家都知道视频播放适配最大的播放屏幕那样是最好的。从网上多方查找资料,查到了这么一篇文章:
  1. 最终,根据此需求处理如下: 首先,确保App本身应该允许转屏切换:

  2. 我的App里面UITabBarController是根视图控制器,所以首先创建一个UITabBarController的子类,并设定允许转屏:

    (这些要放在根视图控制器里面, 如果你的应用根视图是UINavigationController, 就放在那里面就好)

#pragma mark 转屏方法重写
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.viewControllers.firstObject supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate{
    return self.viewControllers.firstObject.shouldAutorotate;
}
  1. 接着,我的tabbarController里面每个子控制器又都是UINavigationController进行界面push切换的,所以首先创建一个UINavigationController的子类,并设定允许转屏:
//self.topViewController是当前导航显示的UIViewController,这样就可以控制每个UIViewController所支持的方向啦!

-(BOOL)shouldAutorotate{

    return [self.topViewController shouldAutorotate];

}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {

    return [self.topViewController supportedInterfaceOrientations];

}
  1. 在你想转屏切换的ViewController上可以照这样重写(允许左右横屏以及竖屏):
- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
  1. 到视频播放界面要设置为横屏啦(我的视频播放只要横屏就好^_^)
// 是否支持屏幕旋转
- (BOOL)shouldAutorotate {

    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeRight;
}

注意:跳转到播放器要使用模态进来, 用Push会报错

[self presentViewController:playerVC animated:YES completion:nil];

时间: 2024-07-31 23:38:50

iOS9横屏竖屏设置的相关文章

Android和iOS中Cocos2dx的横屏竖屏设置

一.横屏.竖屏设置 1.android AndroidManifest.xml文件中, screenOrientation="landscape" 为横屏, screenOrientation="portrait"为竖屏 2.iOS - (NSUInteger) supportedInterfaceOrientations{ #ifdef __IPHONE_6_0 // 横屏显示 // return UIInterfaceOrientationMaskLandsca

Android横屏竖屏设置

Android横竖屏设置: 方法一:onCreate()中 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //横屏 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //竖屏 方法二:AndroidManifest.xml中 android:screenOrientation="landscape" //横屏 an

【转】Android 模拟器横屏竖屏切换设置

http://blog.csdn.net/zanfeng/article/details/18355305# Android 模拟器横屏竖屏切换设置时间:2012-07-04   来源:设计与开发   作者:Daniel   点击:5571 摘要:  Android 模拟器旋转,横屏.竖屏切换设置,android 横屏布局,android 横屏模式,android 模拟器,android 模拟器横屏,android 模拟...       Android 模拟器旋转,横屏.竖屏切换设置,andr

cocos2d-x 设置屏幕方向 横屏 || 竖屏

cocos2d-x 设置屏幕方向 横屏 || 竖屏 需要根据各个平台分别进行设置. android 修改项目根目录 proj.android\AndroidManifest.xml 文件中的android:screenOrientation属性值,portrait 为竖屏,landscape为横屏 Windows 直接用cocos引擎接口中的GLView::createWithRect方法指定窗口大小,需要注意的是,该方法在android环境下会报错,并导致程序崩溃,所以我们需要在代码里面这么写

Cocos2dx开发windows phone时,VS2013设置为横屏竖屏问题

1.首先打开自己的windows phone的项目: 2.把项目打开,可看到如下的结构: 3.然后点击MainPage.xaml文件,可以看到如下结构: 然后左边是显示的模拟器,右边是代码,Landscape表示的是横屏,Portrait表示的是竖屏,如图所示: 这样就可以设置横屏竖屏了,如果你只是点击模拟器中的旋转来调试横屏竖屏,根本就没用,还是要代码才能解决吧: 这是在移植wp8的时候一些总结,在移植过程中,各种坑爹的语法都有,有些改了就可以用了,但也许你不知道为什么, 哈哈,真是,可能是兼

手机横屏竖屏css

@media是css3中新定义的,功能非常强大,顾名思义PC是无法匹配横竖屏的,所以orientation只对移动设备起效. 1.头部声明 复制代码 代码如下: <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no,maximum-scale=1.0"> 加到 复制代码 代码如下: <head></head> 2.

HTML5中判断横屏竖屏

HTML5中判断横屏竖屏 在移动端中我们经常碰到横屏竖屏的问题,那么我们应该如何去判断或者针对横屏.竖屏来写不同的代码呢. 这里有两种方法: 一:CSS判断横屏竖屏 写在同一个CSS中 1 2 3 4 5 6 @media screen and (orientation: portrait) {   /*竖屏 css*/ } @media screen and (orientation: landscape) {   /*横屏 css*/ } 分开写在2个CSS中 竖屏 1 <link rel=

Android学习笔记(三六):横屏竖屏的切换

1.准备环境 对模拟器,只要“Ctrl+F12“,就可以可以实现竖屏(portrait)和横屏(landscape)的切换. 2.UI的屏幕切换实现 下面一个简单的例子,如图. 我们需要写两个Android XML文件,假定文件为chapter_19_test1.xml,放在常规目录位置layout/内容如下: [plain] view plaincopy <?xml version="1.0" encoding="utf-8"?> <Linear

Phonegap 禁止手机横屏竖屏自动旋转

方法: 在AndroidManifest.xml的<activity>标签里面加入下面代码 android:screenOrientation=”portrait”属性即可(portrait是纵向,landscape是横向),事例代码如下: <activity android:name="com.example.test.MainActivity" android:label="@string/app_name" android:screenOri