在ios6中“屏幕旋转控制”支持 nav Push某个vc单独旋转

在ios6中如果要实现设备“屏幕旋转”的效果,需要在该Controller中使用以下三个方法:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//ios<6.0
- ( BOOL )shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
        //return ;
}
 
//ios>6.0
- ( BOOL )shouldAutorotate
{
        //return;
}
- ( NSUInteger )supportedInterfaceOrientations
{
    // return
}
但如果想要控制“UINavigationController”直接在Contoller中使用这三个方法,将会不起作用,原因是ios6中“UINavigationController”并不支持- (BOOL)shouldAutorotate、- (NSUInteger)supportedInterfaceOrientations个方法,如果您想要控制其旋转,必须为其添加一个category,使其支持这个三个方法。
然后 用这个navController来初始化rootVC ,并在VC在写上如上3个方法,就可以控制它们的单独旋转方向了。
?

@interface NavViewController (IOS6)  //支持某个vc单独旋转 ,还需要在VC里写上那3个支持旋转方法

-(BOOL)shouldAutorotate;


-(NSUInteger)supportedInterfaceOrientations;


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;


@end


@implementation NavViewController (IOS6)


-(BOOL)shouldAutorotate

{

    return [[self.viewControllers lastObject] shouldAutorotate];

}


-(NSUInteger)supportedInterfaceOrientations

{

    return [[self.viewControllers lastObject] supportedInterfaceOrientations];

}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];

}



@end


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值