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

来源:互联网 发布:中国人开发的编程语言 编辑:程序博客网 时间:2024/05/21 22:43
在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 0