UITabBarController旋转问题

来源:互联网 发布:stm8l编程手册 编辑:程序博客网 时间:2024/05/16 06:17

这个问题网上一下就能找到解决办法。

原文的连接地址:http://blog.csdn.net/studyrecord/article/details/6525441

1、默认的UITabBarController不支持四个方向,但可以给UITabBarController增加一个类别,实现旋转;具体做法:

 

     在工程添加一个.h和.m文件如下:

 

 

//Rotation.h

 

#import <Foundation/Foundation.h>

@interface UITabBarController(Rotation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;

@end

//Rotation.m

#import "Rotation.h"

@implementation UITabBarController(Rotation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return YES;

}

@end

 

重新编译,运行后UITabBarController就可以支持四个方向了;

 

2、进一步,如果UITabBarController包含多个ViewController,如A,B,C三个;但我们只想A,B,支持四个方向,而C只支持一个方向,则在

 

//Rotation.m

 

 

 

#import "Rotation.h"

@implementation UITabBarController(Rotation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

if([[self selectedViewController] isKindOfClass:[C class]]){

return NO;

}

return YES;

}

@end


原创粉丝点击