什么时候rootViewController至tabbarController时刻,控制屏幕旋转法
2024-08-28 06:08:18
于ios6后,ios系统改变了屏幕旋转的方法,假设您想将屏幕旋转法,在需求rootvc里面制备,例如
UIViewController *viewCtrl = [[UIViewController alloc] init];
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:viewCtrl];
if ([window respondsToSelector:@selector(setRootViewController:)]) {
self.window.rootViewController = navCtrl;
} else {
[self.window addSubview:navCtrl.view];
}
当root为nav时,你要建立一个nav的子类,进行改动,假设是vc时,直接能够在vc里进行改动,网上已经有非常多的样例了,但假设是tabbar里面嵌套这非常多nav和vc,nav里又有vc我们要怎么弄呢,以下是我调研的一些方法,就是用几个category对nav和tabbarController进行类别的编写,让他们能够分别相应子视图的旋转方向
UITabBarController+autoRotate
@interface UITabBarController (autoRotate) -(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations; @end #import "UITabBarController+autoRotate.h" @implementation UITabBarController (autoRotate) - (BOOL)shouldAutorotate {
return [self.selectedViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.selectedViewController supportedInterfaceOrientations];
} @end
UINavigationController+autoRotate.h
@interface UINavigationController (autoRotate) -(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations; @end @implementation UINavigationController (autoRotate) - (BOOL)shouldAutorotate {
return [self.visibleViewController shouldAutorotate];
} - (NSUInteger)supportedInterfaceOrientations {
return [self.visibleViewController supportedInterfaceOrientations];
} @end
UIViewController1.m - (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;;
}
UIViewController2.m - (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
參考文章:IOS6屏幕旋转具体解释(自己主动旋转、手动旋转、兼容IOS6之前系统) , 在IOS应用中从竖屏模式强制转换为横屏模式 , http://stackoverflow.com/questions/12522903/uitabbarcontroller-rotation-issues-in-ios-6
版权声明:本文博主原创文章。博客,未经同意不得转载。
最新文章
- React之Froms
- linux 查看磁盘剩余命令
- Porter/Duff,图片加遮罩setColorFilter
- Java线程之CompletionService
- Python 中的 TK编程
- Go 接口转换的一个例子
- gulp+browserSync+nodemon 实现express 全端自动刷新的实践
- Eclipse选中变量名,相同变量都变色显示 的设置
- FZU 2170 花生的序列(动态规划)
- 关于SpringMVC中text/plain的编码导致的乱码问题解决方法
- [置顶]
 xamarin android自定义标题栏(自定义属性、回调事件)
- Python+selenium自动化测试中Windows窗口跳转方法
- ASP.NET machineKey的作用和使用方法
- Nginx FIND_CONFIG阶段
- LeetCode 883 Projection Area of 3D Shapes 解题报告
- 在VS 2010上搭建Windows Phone 7开发平台
- Hashing图像检索源码及数据库总结
- 分布式缓存设计:一致性Hash算法
- javascript获取网址参数
- 关于iOS UIWebView 加载网页,点击网页内某些控件导致 Application 'UIKitApplication:xxx.xxx.xxx' was killed by jetsam.