iOS 6横屏竖屏展示

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了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值