Cocos2D-iphone 开发之 设置屏幕方向(Interface Orientation)
来源:互联网 发布:诺基亚e71软件下载 编辑:程序博客网 时间:2024/04/29 12:50
简单记录一下今天遇到的一个应用程序屏幕方向的问题。
一般情况下,应用程序都会指定方向,例如横向(landscape),或者竖向(portrait)。
那么如何设定呢?
注意:这里要区分不同版本的。
找到AppDelegate.m文件中
// The available orientations should be defined in the Info.plist file. 支持的方向需要在 Info.plist 文件中定义// And in iOS 6+ only, you can override it in the Root View controller in the "supportedInterfaceOrientations" method.// Only valid for iOS 6+. NOT VALID for iOS 4 / 5.-(NSUInteger)supportedInterfaceOrientations { //这里指定是竖向,包括两个UIInterfaceOrientationMaskPortrait 和 UIInterfaceOrientationMaskPortraitUpsideDown// iPhone onlyif( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ) return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; //iPad only return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;}// Supported orientations. Customize it for your own needs// Only valid on iOS 4 / 5. NOT VALID for iOS 6.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ //这里也指定是竖向// iPhone onlyif( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )return UIInterfaceOrientationIsPortrait(interfaceOrientation);// iPad only return UIInterfaceOrientationIsPortrait(interfaceOrientation); //这个方法指定是横向// return UIInterfaceOrientationIsLandscape(interfaceOrientation);}
看到上面的代码就知道,第一个方法是用于设定iOS6+版本的,第二个方法是设定iOS4/5版本的。
对于第一个方法中 UIInterfaceOrientationMask 根据需要选择 return
typedef enum { UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait), UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),} UIInterfaceOrientationMask;
大概就是这样啦!
- Cocos2D-iphone 开发之 设置屏幕方向(Interface Orientation)
- 设置iphone屏幕方向
- cocos2d 设置屏幕默认方向
- cocos2d 设置屏幕默认方向
- iPhone开发之小技巧:强制转换屏幕方向(3)
- 【Orientation】详解Android中的屏幕方向
- Orientation Auto Rotation旋转屏幕crash问题(Unity3D开发之十四)
- SpriteKit游戏开发点滴(1) 如何设置屏幕方向
- Windows Phone 开发 设置屏幕方向 & 全屏
- quick-cocos2d-x 如何设置游戏的屏幕方向
- Cocos2d-x中移植到Android真机上屏幕方向设置
- quick-cocos2d-x 如何设置游戏的屏幕方向
- Cocos2d-iphone 开发之(3) 了解Cocos2d核心类
- iphone开发之屏幕截图
- iPhone开发之屏幕旋转
- Interface Orientation
- iphone游戏开发之cocos2d
- iPhone软件开发之Interface Builder
- hdu1263 水果(结构体排序)
- csapp2e 家庭作业 6.40
- AndroidStudio如何导入Eclipse中的Android项目
- IDENTITY_INSERT 设置OFF 不能插入列标识符解决办法
- 视觉直观感受7种常用的排序算法
- Cocos2D-iphone 开发之 设置屏幕方向(Interface Orientation)
- Server Tomcat v6.0 Server at localhost failed to start.
- 将HTML特殊转义为实体字符的两种实现方式
- 当程序崩溃的时候怎么办 part-1
- Unable to acquire Oracle environment handle
- 一个java开发人员 的方向
- net.sf.json.JSONException: java.lang.reflect.InvocationTargetException
- Android.mk 浅析 模块编译Makefile编写
- 当程序崩溃的时候怎么办 Part-2