xcode 版本4.5     模拟器:6.0

项目需求:刚进去界面横屏,从这个界面进去的界面全是竖屏。

程序的根控制器用了UINavigationController。下面是代码:

1.在appdelegate中添加代码:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

returnUIInterfaceOrientationMaskAll;

}

2.给 UINavigationController添加个category,在实现文件中添加如下代码:

-(BOOL)shouldAutorotate

{

return [[selftopViewController] shouldAutorotate];

}

-(NSUInteger)supportedInterfaceOrientations

{

return [[selftopViewController] supportedInterfaceOrientations];

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

return [[selftopViewController] preferredInterfaceOrientationForPresentation];

}

3.在需要横屏的地方添加(竖屏可以更换方向):

-(NSUInteger)supportedInterfaceOrientations{

returnUIInterfaceOrientationMaskLandscapeRight;  // 可以修改为任何方向

}

-(BOOL)shouldAutorotate{

returnYES;

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return interfaceOrientation == UIInterfaceOrientationLandscapeRight;

}

4.最重要的是:页面之间切换不能用导航控制器切换,必须使用:

[selfpresentViewController:navigationController animated:YEScompletion:Nil];

ios 6 横竖屏转换的更多相关文章

  1. iOS强制横竖屏转换

    https://www.jianshu.com/p/d6cb54d2eaa1  这篇文章给出的方案是可行的. 经测试,想要第一个界面强制横屏,第二个界面强制竖屏, dismiss掉之后回到第一个界面依 ...

  2. [iOS]终极横竖屏切换解决方案

    [iOS]终极横竖屏切换解决方案 大家的项目都是只支持竖屏的吧?大多数朋友(这其中当然也包括博主),都没有做过横屏开发,这次项目刚好有这个需求,因此把横竖屏相关的心得写成一遍文章供诸位参考. 01.综 ...

  3. Android Activity横竖屏转换的生命周期

    新创建一个Activity,用来此次测试. 先贴代码 package com.hugo.apj.activitylifetest; import android.support.v7.app.AppC ...

  4. 代码处理 iOS 的横竖屏旋转

    一.监听屏幕旋转方向 在处理iOS横竖屏时,经常会和UIDeviceOrientation.UIInterfaceOrientation和UIInterfaceOrientationMask这三个枚举 ...

  5. iOS 横竖屏切换(应对特殊需求)

    iOS 中横竖屏切换的功能,在开发iOS app中总能遇到.以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰到了,demo尝试了几种情况,这里就做下总结.注意 横屏两种情况是反的你知道吗? UI ...

  6. 2014-08-28——Android和IOS的简单嗅探,以及横竖屏的捕获思路

    一般通过navigator.userAgent来嗅探Android系统和IOS系统: if(/android/i.test(navigator.userAgent)){ //android } if( ...

  7. iOS 中各种横竖屏切换总结

    iOS 中横竖屏切换的功能,在开发iOS app中总能遇到.以前看过几次,感觉简单,但是没有敲过代码实现,最近又碰到了,demo尝试了几种情况,这里就做下总结.注意 横屏两种情况是反的你知道吗? UI ...

  8. 基于zepto判断mobile的横竖屏状态

    借用jquery mobile中的代码,删除了一些多余的部分,简单的基于zepto的模块 var CheckOrientation = (function(){ var win = $( window ...

  9. zepto判断手机横竖屏

    var CheckOrientation = (function(){ var win = $( window ), get_orientation, last_orientation, initia ...

随机推荐

  1. 130831组队赛-Regionals 2011, Asia - Kuala Lumpur

    A.Smooth Visualization 简单模拟题,不多说了. #include<iostream> #include<cstdio> #include<algor ...

  2. 在SharePoint 2013 中使用文档库Scheduling (计划公布功能)

    本文讲述在SharePoint2013 中使用文档库Scheduling (计划公布功能)的步骤和注意的事项. 文档库Scheduling (计划公布功能) 用于设定当文档通过审批后特定的时间区间内才 ...

  3. web前端网页开发一般过程

    看见很多新手同学前端开发,效率比较慢.总是拿起代码就敲,不分析,没有逻辑,反而使效率变慢.所谓磨刀不误砍柴工,有一个良好的过程,才是最主要的: 1.分析平面效果图,在草稿纸上画出基本结构图 2.建立项 ...

  4. OpenCV中遇到Microsoft C++ 异常 cv::Exception

    我在实现<OpenCV2计算机视觉编程手册>第2章 2.2 节 存取像素值 中的椒盐噪声例子中遇到的程序错误. 原始输入程序: #include <opencv2/core/core ...

  5. jquery如何在加载完iframe的内容后才进行下一步操作

    为iframe添加onload事件 ie使用attachEvent("onload",function(){}) firefox.chrome使用addEventListener( ...

  6. 使用JDBC对数据库实现批处理操作

    本篇讲述如何使用JDBC对数据库实现批处理操作.很多时候单条SQL命令不能满足我们的需求,我们需要对数据库一次实现很多操作,需要发送一批SQL命令给数据库执行. 而JDBC也提供了相应的方法给我们实现 ...

  7. linux 解压操作命令

    http://apps.hi.baidu.com/share/detail/37384818 download ADT link http://dl.google.com/android/ADT-0. ...

  8. ADOConnection数据库连接池

    unit AdoconnectPool; interface uses Classes, Windows, SysUtils, ADODB, IniFiles, forms; type TADOCon ...

  9. vs2012 不显示最近项目

    visual studio起始页不显示最近使用项目的解决办法方法一 1.开始 → 运行 → 输入 regedit 回车,打开注册表编辑器. 2.定位到 HKEY_CURRENT_USER/Softwa ...

  10. Windows 编程之 对话框总结

    关于对话框 1 对话框种类 对话框也是一种资源,Windows中对话框分为模态的和非模态的,以及Windows系统中已经定义好的那些通用对话框,比方打开文件,目录,调色板,字符串查找等. 2 模态对话 ...