您的位置:首页 > 移动开发 > IOS开发

iOS 6横屏竖屏展示

2015-02-05 11:53 162 查看


1.用UINavigationController处理2个以上ViewController跳转时,原来横屏的界面被转成了竖屏且无法切换到横屏。

原因是用了[self.window
addSubview:navController.view];

改成:[self.window setRootViewController:navController];

然后在AppDelegate里加:

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

{

return UIInterfaceOrientationMaskLandscape;

}

即可。




iOS6强制旋转屏幕

最近改了一下以前的程序.把程序中用到旋转的地方都新增加上了iOS的旋转方法.

但是有一个问题还是无法解决,在iOS6上强制旋转屏幕,

比如程序刚打开是横屏(只支持横屏).然后点击某个菜单后就强制旋转到竖屏(界面只支持竖屏),

以前的程序中用到的

[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:YES];

目前已经不起任何作用了.然后就改用了

[[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:(id)UIDeviceOrientationPortrait];

这个方法目前已经是苹果的私有方法了.确实能够旋转屏幕,但是会有一些bug存在,

比如目前是横屏状态,但是我手机竖着拿,然后点击菜单切换界面,这时候就不会响应这个方法了.

不知道目前大家在iOS6上都是怎么处理强制旋转屏幕的,大家分享下经验.谢谢!

这个刚好前几天研究了一下

首先在AppDelegate里面

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

{

return UIInterfaceOrientationMaskAll;

}

然后在你不需要旋转的controller 里面

-(NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskPortrait;

}

这样这个controller的view就不旋转了,需要旋转的controller不要加这个就可以了

还有一种情况,当你是用navigationcotroller push出来的controller,如果root controller 加了

-(NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskPortrait;

},那么在它推出来的所有controller都不会旋转,怎么办呢?其实很简单,去将UINavigationController这个类使用Categroy,就添加

-(NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskPortrait;

}

就ok了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: