ios6.0 UINavigationController、UITabBarController 支持屏幕自动旋转问题

1、描述

      self.window.rootViewController = UINavigationController 或 UITabBarController。

或者是混合使用的,如: UINavigationController 下包含UITabBarController

     因  UINavigationController、UITabBarController 也是 UIViewController,所以会覆盖其子页面的旋转方法

2、解决,添加类

@interface UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

@end

#import "UINavigationController+Rotation_IOS6.h"

@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate {
    
    NSLog(@"UINavigationController 100");
    // 不想其子页面支持旋转, 可直接返回 NO
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations {
    NSLog(@"UINavigationController 200");
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    NSLog(@"UINavigationController 300");
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end

@interface UITabBarController (Rotation_IOS6)

-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;

@end

@implementation UITabBarController (Rotation_IOS6)

-(BOOL)shouldAutorotate {
    NSLog(@"UITabBarController 100");
    // 不想其子页面支持旋转,可直接返回 NO
    return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations {
     NSLog(@"UITabBarController 200"); 
    //return UIInterfaceOrientationMaskPortrait;
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    NSLog(@"UITabBarController 300"); //return UIInterfaceOrientationPortrait;
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}@end

 3、AppDelegate.m 中 使用 

#import "UINavigationController+Rotation_IOS6.h"
#import "UITabBarController+Rotation_IOS6.h"

4、自定义的 UIViewController 中再设置对应的旋转方法

- (BOOL)shouldAutorotate {
- (NSUInteger)supportedInterfaceOrientations{
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{

5、ios5 支持屏幕旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    return (interfaceOrientation == UIInterfaceOrientationPortrait);  
}  


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值