Force IOS 6 force device orientation to landscape
来源:互联网 发布:优化方案答案物理答案 编辑:程序博客网 时间:2024/05/01 05:26
http://stackoverflow.com/questions/12640870/ios-6-force-device-orientation-to-landscape
Ok, folks, I will post my solution.
What I have:
- A view based application, with several view controllers. (It was navigation based, but I had to make it view based, due to orientation issues).
- All view controllers are portrait, except one - landscapeLeft.
Tasks:
- One of my view controllers must automatically rotate to landscape, no matter how the user holds the device. All other controllers must be portrait, and after leaving the landscape controller, the app must force rotate to portrait, no matter, again, how the user holds the device.
- This must work as on IOS 6.x as on IOS 5.x
Go!
Define macros that will detect the IOS version:
Create an NSObject class "Constants", delete Constants.m, you need Constants.h only. Delete all Constants.h's code and write this:
#define IOS_OLDER_THAN_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0 )#define IOS_NEWER_OR_EQUAL_TO_6 ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0 )
Import Constants.h in all your .m files where you will override autorotation methods.
In all your PORTRAIT view controllers override autorotation methods like this:
#ifdef IOS_OLDER_THAN_6- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return (toInterfaceOrientation == UIInterfaceOrientationPortrait);}#endif#ifdef IOS_NEWER_OR_EQUAL_TO_6-(BOOL)shouldAutorotate { return YES;}- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait;}#endif
You can see the 2 approaches: one for IOS 5 and another For IOS 6.
The same for your LANDSCAPE view controller, with some additions and changes:
#ifdef IOS_OLDER_THAN_6- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ [image_signature setImage:[self resizeImage:image_signature.image]]; return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);}#endif#ifdef IOS_NEWER_OR_EQUAL_TO_6-(BOOL)shouldAutorotate { return YES;}- (NSUInteger)supportedInterfaceOrientations { [image_signature setImage:[self resizeImage:image_signature.image]]; return UIInterfaceOrientationMaskLandscapeLeft;}#endif
- Force IOS 6 force device orientation to landscape
- --force
- CPrintDlg to appear with Landscape printing orientation
- How to force an iframe to reload?
- computeValuesWithHarfbuzz -- need to force to single run
- How to force NSLocalizedString to use a specific language iOS APP内国际化
- bring (force) a Window to the foreground?
- Responding to a Brute Force SSH Attack
- Two ways to force an IGMP join
- How to Force Shutdown WebLogic Managed Server
- iOS: Force audio output to speakers while headphones are plugged in
- /FORCE:MULTIPLE
- FileChannel Force
- force 指令
- Force close
- d3 force
- Brute Force
- db2stop force
- 黑马程序员--03.Java面向对象--01.【OOP基本概念】【匿名对象】【封装】【构造函数】【this关键字】
- birt隔行换色
- 1006. 换个格式输出整数 (15)
- 怎么开始一个项目?-------一个Web项目雏形的描述 2
- 【23】网络编程1_UDP数据传输,TCP数据传输
- Force IOS 6 force device orientation to landscape
- Good Substrings CF271D
- zz:Stanford-CV华人教授李飞飞写给她学生的一封信,如何做好研究以及写好PAPER,受益匪浅
- 唯美红尘
- 【24】网络编程2_TCP并发上传图片和登录,Tomcat服务器,自定义IE,域名解析
- zoj1154-Niven Numbers
- 矩阵中的DP题 放象棋
- 【25】正则表达式
- Android架构: MVC 模式加载数据 前台显示