typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {
UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown,
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
};

UIInterfaceOrientation enum

使App支持旋转
有两种方法:
1.选择Project->Target->General->Deployment Info->Device Orientation,勾选需要支持的屏幕方向,比如
     Portrait
     Upside Down
     Landscape Left
     Landscape Right
2.在AppDelegate.m文件中,添加方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscape;
}
以上面中的设置为例
启动画面的方向取决于方法一,启动画面之后的Window方向取决于方法二,如果未实现方法二,则取决于方法一
 
大部分页面为Portrait,个别页面为Landscape
例如AppDelegate中的window的rootViewController为TabBarController,则TabBarController的ViewControllers的旋转方向都取决于TabBarController,因此需要在TabBarController中实现以下方法
#import "TYSXTabBarController.h"

#define kTabBarColor [UIColor colorWithRed:0.953f green:0.953f blue:0.953f alpha:1.00f]
#define kTintColor [UIColor colorWithRed:0.914f green:0.000f blue:0.294f alpha:1.00f] @implementation TYSXTabBarController - (void)viewDidLoad
{
[super viewDidLoad];
self.tabBar.translucent = NO;
[self.tabBar setBarTintColor:kTabBarColor];
self.tabBar.tintColor = kTintColor;
} - (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
} - (BOOL)shouldAutorotate
{
return YES;
} - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
@end

TabBarController.m

这样,TabBarController下的所有页面就都只能是竖向了。

如何让某个页面只能是横向的呢?

以全屏播放页面(FullScreenViewController)为例,Present显示该页面,如此,播放页面就与TabBarController独立开了,在FullScreenViewController.m中实现以下方法

@implementation FullScreenViewController

- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
} - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
} @end

FullScreenViewController.m

UIInterfaceOrientation over iOS6 (应用旋转屏幕)的更多相关文章

  1. Android 旋转屏幕--处理Activity与AsyncTask的最佳解决方案

    一.概述 运行时变更就是设备在运行时发生变化(例如屏幕旋转.键盘可用性及语言).发生这些变化,Android会重启Activity,这时就需要保存activity的状态及与activity相关的任务, ...

  2. android手机旋转屏幕时让GridView的列数与列宽度自适应

    无意中打开了一年前做过的一个android应用的代码,看到里面实现的一个小功能点(如题),现写篇文章做个笔记.当时面临的问题是,在旋转屏幕的时候需要让gridview的列数与宽度能自适应屏幕宽度,每个 ...

  3. Android——旋转屏幕导致Activity重建解决方法

    Android开发文档上专门有一小节解释这个问题.简单来说,Activity是负责与用户交互的最主要机制,任何“设置”(Configuration)的改变都可能对Activity的界面造成影响,这时系 ...

  4. iOS两个强制旋转屏幕的方法

    第一个: // 状态栏动画持续时间 CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimation ...

  5. Android开发 旋转屏幕导致Activity重建解决方法(转)

     文章来源:http://www.jb51.net/article/31833.htm Android开发文档上专门有一小节解释这个问题.简单来说,Activity是负责与用户交互的最主要机制,任何“ ...

  6. Xamarin.Android 开发中遇到旋转屏幕错误

    错误信息 : System.NotSupportedException: Unable to find the default constructor on type App5.MyFragment. ...

  7. Unity3D研究院之设置自动旋转屏幕默认旋转方向

    如下图所示,在处理屏幕默认旋转方向的时候可以在这里进行选择,上下左右一共是4个方向. 策划的需求是游戏采用横屏,但是要求支持两个方向自动旋转,如下图所示,我的设置是这样的. Default Orien ...

  8. Android 最基础生命周期及旋转屏幕问题

    public class MainActivity extends Activity { private static final String TAG ="MainActivity&quo ...

  9. Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容

    Android 禁止屏幕旋转 & 旋转屏幕时保持Activity内容   1.在应用中固定屏幕方向.        在AndroidManifest.xml的activity中加入:     ...

随机推荐

  1. C语言中常用的字符串操作函数

    程序开头要声明 #include <string.h> 函数名: stpcpy 功 能: 拷贝一个字符串到另一个 用 法: char *stpcpy(char *destin, char ...

  2. C++函数模版的简单使用

    模版算是C++的独有特性吧,也算是C++中比较难的地方,我平时开发的时候用的非常少,或者几乎没有用到,需要模版的地方是能看懂框架中相关的代码: 模版函数相对还是很简单的,引入模版的目的在于代码的重用: ...

  3. __x__(2)0905第二天__计算机软件和硬件

    计算机(Computer)由硬件和软件组件,没有软件的计算机称为 裸机, 计算机的软件包括操作系统(OS)和应用软件(Software). 操作系统(Operating System,简称OS) 是管 ...

  4. CentOS 7下简单的Ansible使用入门

    1.配置hosts文件,Ansible依赖hosts文件进行主机通讯,不能直接在命令行上直接输入IP. vi /etc/ansible/hosts hosts文件格式如下: [servers] hos ...

  5. Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

    Trident (又称为MSHTML),是微软的窗口操作系统(Windows)搭载的网页浏览器—Internet Explorer的排版引擎的名称. 它的第一个版本随着1997年10月Internet ...

  6. grep/pgrep/egrep/fgrep

    Differences between grep, pgrep, egrep, and fgrep (Linux): grep grep is an acronym that stands for & ...

  7. RxJava2 源码解析(一)

    概述 最近事情太多了,现在公司内部的变动,自己岗位的变化,以及最近决定找工作.所以博客耽误了,准备面试中,打算看一看RxJava2的源码,遂有了这篇文章. 不会对RxJava2的源码逐字逐句的阅读,只 ...

  8. Android Studio 3.1 正式版

    欢迎大家推荐自己在Android开发过程中用的好用的工具.学习开发教程.用到设计素材.如果你觉得本站对你有用,你可以点击底部的分享按钮,把本站分享到社交网络让你的小伙伴和更多的人知道. 或者可以考虑捐 ...

  9. 救基友3(三维BFS)

    救基友记3 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述   话说CZ因为不守基道.被妖怪抓走了.好基友WP在努力讨好高富帅 ...

  10. 用 CPI 火焰图分析 Linux 性能问题

    https://yq.aliyun.com/articles/465499 用 CPI 火焰图分析 Linux 性能问题   yangoliver 2018-02-11 16:05:53 浏览1076 ...