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. ab,qps 并发连接数

    并发连接数 = pv / 统计时间 * 页面衍生连接次数 * http响应时间 * 因数 / 其他web服务器 数量 pv = 并发连接数 * 统计时间 * 其他web服务器 数量/ 页面衍生连接次数 ...

  2. Flask的使用

    一.路由系统 1.子域名的配置 """ 可传入的参数: @app.route('/user/<username>') @app.route('/post/&l ...

  3. Putty的用法

    大致内容罗列如下: ·        最简单的使用,登录 SSH主机 ·        中文乱码的处理 ·        PuTTY常用配置的说明 ·        复制.粘贴 ·        保存 ...

  4. 2016年3月8日Android实习日记

    1.出现fragment后台栈的bug. bug描述:当点击加入后台栈的操作按钮改变指定控件的内容之后,称为A操作:接下来又点击其它没有操作后台栈的按钮来修改原来指定的控件内容,称为B操作.然后点击b ...

  5. 喵哈哈村的魔法考试 Round #13 (Div.2) 题解

    喵哈哈村的木星传说(一) 旋转90°,找找规律就知道(x,y)->(n-1-y,x) 然后输出就好了. #include<bits/stdc++.h> using namespace ...

  6. 在现实面前,IT从业者的无奈

    话题:在中国,有多少程序员干到40了? 作者:匿名用户 链接:https://www.zhihu.com/question/33953081/answer/349839986 学历低,计算机理论不高, ...

  7. Linux进程优先级系统——设置实时进程优先级

    前言 最近研发的产品出了点小bug,最后查到根本原因是,其中一个进程A使用基于FIFO的实时进程优先级,而另一个进程B是使用普通调度的进程优先级,而A和B两个进程是互相通信的,进程B会被饿死,而进程A ...

  8. react-native开源组件react-native-wechat学习

    转载链接:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/react-native-open-source-components-r ...

  9. eclipse和jdk的版本问题,比如printf()出错

    1.右键项目选中properties 2.Java Builder Path >>>Libraries>>>选中JRE Syste Library[jre7]然后r ...

  10. php中call_user_func 与 call_user_func_array的使用

    call_user_func()是利用回调函数处理字符串,call_user_func_array是利用回调函数处理数组. // 1. 调用自定义函数 function test($a, $b) { ...