iOS 开发 - 让 UITabContorller 不同的tab 分别支持不同的横竖屏样式
来源:互联网 发布:便知天下事 编辑:程序博客网 时间:2024/06/06 17:19
直接上代码
在 UITabBarViewController.m 中
#import "ZZTabBarViewController.h"
#import "LeftTabViewController.h"
#import "RightTabViewController.h"
@interface ZZTabBarViewController ()
@end
@implementation ZZTabBarViewController
// 屏幕旋转
- (BOOL)shouldAutorotate {
returnYES;
}
// 根据selectedIndex 确定支持的屏幕方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
if (self.selectedIndex ==0) {
// tab 0 // 所有屏幕方向
returnUIInterfaceOrientationMaskAll;
} else {
// 只支持竖屏
returnUIInterfaceOrientationMaskPortrait;
}
}
// viewDidLoad 中创建 tabBar 两个子视图控制器
- (void)viewDidLoad {
[superviewDidLoad];
self.tabBar.barTintColor = [UIColorblackColor];
self.tabBar.tintColor = [UIColorwhiteColor];
LeftTabViewController *left = [[LeftTabViewControlleralloc]init];
left.tabBarItem.title =@"左视图";
RightTabViewController *right = [[RightTabViewControlleralloc]init];
right.tabBarItem.title =@"右视图";
self.viewControllers =@[left, right];
}
// 重载 selectedViewController 的 setter, 目的是 当由 tab 0 到 tab 1 时, 若设备是横屏的, 则转为竖屏
- (void)setSelectedViewController:(__kindofUIViewController *)selectedViewController {
[supersetSelectedViewController:selectedViewController];
UIDeviceOrientation orientation = [UIDevicecurrentDevice].orientation;
if (self.selectedIndex ==1 &&UIDeviceOrientationIsLandscape(orientation)) {
// 由于属性 orientation是只读的,所以采用以下方法实现
if ([[UIDevicecurrentDevice]respondsToSelector:@selector(setOrientation:)]) {
SEL selector =NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocationinvocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevicecurrentDevice]];
int val =UIInterfaceOrientationPortrait;
[invocation setArgument:&valatIndex:2];
[invocation invoke];
}
}
}
- iOS 开发 - 让 UITabContorller 不同的tab 分别支持不同的横竖屏样式
- 横竖屏不同的情况来适配样式
- 让iOS应用支持不同版本的系统与设备
- 让iOS应用支持不同版本的系统与设备
- 让iOS应用支持不同版本的系统与设备
- 让iOS应用支持不同版本的系统与设备
- 让 cocos2d 开发的程序支持不同分辨率的图片
- 让label中的不同字符显示不同的样式
- 让android支持不同的语言、屏幕
- iOS - 同一个Label的不同样式显示
- iOS 不同系统横竖屏转动
- 加载不同的样式
- 不同的分页样式
- iOS [UIScreen mainScreen].bounds 横竖屏在不同版本获取屏幕大小不对的问题
- 如何让自己开发的android支持多种不同的手机屏幕(supporting Multiple Screens)
- 支持不同的设备
- 支持不同的设备
- 支持不同的版本
- Storm实时计算:流操作入门编程实践
- 项目1.3 验证二叉排序树
- 平衡二叉树
- C++容器三
- PHP的基本语法——PHP语言标记及指令分隔符“分号”
- iOS 开发 - 让 UITabContorller 不同的tab 分别支持不同的横竖屏样式
- 互联网分布式应用集中式session的实现方式?
- 使cocopods管理开源库编译出现Library not found for -lPods问题的解决方法
- ExtJs入门
- 第14周项目1-验证算法
- Linux内核spin_lock、spin_lock_irq 和 spin_lock_irqsave 分析
- 跟人说话要说正向的,不然别人会觉得你不靠谱
- Android获取应用版本信息
- 工作过程中积累的书签(链接)