旧项目在iOS6中无法旋转的解决办法

问题解决:iOS6下UIWebView嵌vedio标签播放视频屏幕不旋转 项目默认为竖屏,在iOS6下UIWebView嵌Vedio标签播放视频屏幕不旋转,iO http:// S5没有问题。 一、版本判断宏 // iOS版本=== #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] 阅读详情

之前做的一个iPad上的app,在最新的sdk下重新编译,出现无法旋转的情况。查看了一些文档,由于iOS6在旋转处理的api有了变化,之前处理旋转的函数shouldAutorotateToInterfaceOrientation:在iOS6下无效,由supportedInterfaceOrientations 和 shouldAutorotate替代。

于是在对应的viewcontroller上增加了这两个函数,但还是无效。函数有响应,但没达到旋转的效果。

继续查找一些资料,在一篇文章中找到原因,由于旧的项目没有rootViewController,而iOS6判断是否需要旋转是根据rootViewController来判断的。

于是在代码中手动添加self.window.rootViewController=xxxViewController,(xxxViewController为启动的主界面)即可解决。

详细可参考以下文章:

http://blog.csdn.net/bl1988530/article/details/8641099#t1


内容转载如下:

如果你的 iOS App 支持随屏幕旋转而旋转,但是到了 iOS 6 中,发现这个功能不生效了,那么就要检查一下是不是因为旧版本的 Xcode 创建工程的原因。
但是在 iOS SDK Release Notes for iOS 6.0 中的 UIKit 一节中说到“Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.”,并且详细解释中也说明了 iOS 6 中的改动:

More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.
A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change over time. The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style. Moreover, the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method. The system intersects the view controller’s supported orientations with the app’s supported orientations (as determined by the Info.plist file or the app delegate’s application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.
The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller.
The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This makes the caller responsible for ensuring that the status bar orientation is consistent.
For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.


说明中提到,在 iOS 6 中系统会通过查询 rootViewController 来判断是否可以旋转视图,但是在以前,使用 Xcode 创建一个工程时,通常会有以下代码来显示主窗口:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Add the tab bar controller's view to the window and display.
    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];
 
    return YES;
}


在这里,并没有设置 self.window 的 rootViewController,而且在 MainWindow.xib 中,也没在连接 window 的 rootViewController 到默认的 UITabBarController。


因此,我们有两种方法来解决这个问题:


1. 在代码中设置 rootViewController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Add the tab bar controller's view to the window and display.
    self.window.rootViewController = tabBarController;
    [self.window addSubview:tabBarController.view];
    [self.window makeKeyAndVisible];
 
    return YES;
}


2. 在 MainWindow.xib 中连接 window 的 rootViewController。
华为防火墙双ISP出口实战:如何用策略路由实现电信联通流量自动切换(附配置截图) 本文详细解析了华为防火墙在双ISP环境下的智能选路技术,通过策略路由与健康检测的深度应用,实现电信联通流量的自动切换。文章包含实战配置截图,帮助企业解决切换延迟、路径劣化等核心挑战,提升业务连续性。 阅读详情

相关推荐

国产AI芯片实战:用寒武纪MLU370低成本部署DeepSeek-R1,实测推理效果与成本分析

本文详细介绍了寒武纪MLU370芯片在部署DeepSeek-R1大模型时的实战效果与成本优势。通过实测数据对比,MLU370在推理速度、能效比和本地化服务方面表现突出,尤其适合智能客服、内容生成等场景,可显著降低硬件投入和运维成本。

weixin_30613727的博客 461

VC的shouldAutorotate和supportedInterfaceOrientations方法的学习demo

ios屏幕旋转:当全屏模式(此时是横屏模式)时,把app退后台然后再进入app时,横屏模式变成竟然变成了竖屏模式的解决方法。 步骤1:先看下图苹果文档的discussion部分。但这句话应该这样读: ①This method returns the total set of interface orientations supported by the app.意思是该方法返回的是app所支持的界面旋转方向集合。 ②对于When determining whether to rotate a particu

u010919133的专栏 2587

手把手教你用8位单片机IO口直接驱动WS2812灯带(附完整代码和避坑指南)

本文详细介绍了如何使用8位单片机IO口直接驱动WS2812灯带,包括硬件准备、时序生成、色彩引擎与特效算法的实现,以及调试技巧与性能优化。通过汇编语言优化和精确时序控制,实现高效的LED驱动和炫酷的彩虹灯效,适合嵌入式开发者和硬件爱好者参考。

weixin_42696271的博客 309

如何修正iOS6上Oritentation的问题

1.将addSubview修改为setRootViewController [window addSubview: viewController.view];修改如下: if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn't work on iO...

810364804 178

手把手教会你用yolov8从环境配置到检测任务实战

做本文章前,我浏览过很多网上资料,我发现他们总是写的含糊不清,而且实际操作起来就会有各种各样的问题,要么就是根本不适合一些小白,所以我在这里写一篇完全针对小白的yolo从入门到实战。看完本文章后大家都可以实现下图效果,数字识别是一种比较简单的检测任务,其他识别任务学完本例也能够一通百通,大家边做边学,更好的体会yolo的神奇之处。

KevenDuan的博客 2879

SKILL实现电路virtuoso原理图schematic中引脚pin的net自动打上pin label

SKILL实现电路virtuoso原理图schematic中引脚pin的net自动打上pin label

qq_41510657的博客 2627

IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)

转自:http://blog.csdn.net/cococoolwhj/article/details/8208991 概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToInt

张中峰的专栏 5万+

DSP28335 ADC模块实战:从寄存器配置到精准数据采集(附代码详解)

本文详细解析DSP28335的ADC模块配置与数据采集实战,涵盖寄存器设置、采样窗口优化、中断处理及代码实现。重点解决ADC精度问题,如采样窗口不足导致数据偏差,提供完整代码示例和调试技巧,助力工程师实现精准数据采集。

kkk56的博客 873

如何同时支持IOS5和IOS6上的屏幕旋转?

http://blog.csdn.net/world_liu/article/details/8952522 转自:http://iliao.diandian.com/post/2013-02-21/40049597269 1.将addSubview修改为setRootViewController [window addSubview: viewContr

u011248345的专栏 657

Winform利用动画控制实现各种特效

动画绘制控制类代码 using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Threading; using System.Windows.Forms; namespace Mengliao.CSharp.A14 { #region 动画类型枚举 // 本例为了简单起见没有使用见名知意的名称,如用于实际可将这些枚举成员更名

LilyCoder的博客 2504

CarSim仿真高级进阶---VS 命令行

仿真软件作为一种强大的工具,被广泛应用于汽车工程领域,本文将介绍如何使用VS命令行进行CarSim仿真的高级进阶操作,我们将结合相关的源代码和描述,帮助读者更好地理解和应用这一功能。打开Visual Studio,在“文件”菜单下选择“新建”->“项目”,然后选择“控制台应用程序”模板,填写项目名称和位置,点击“确定”按钮创建项目。保存源代码后,点击菜单中的“生成”->“生成解决方案”来构建项目,确保构建成功,没有任何错误。点击“编辑”按钮,在弹出的窗口中点击“新建”按钮。,并拥有有效的许可证。

weixin_50547796的博客 314

ios屏幕旋转设置

// Override to allow orientations other than the default portrait orientation. // This method is deprecated on ios6 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOr

code_monkey的专栏 726

硬件学习手册【总目录】

欢迎大家来到《硬件学习手册》,专栏主要包括 《硬件经验手册》《电子元器件器件手册》《PCB手册》《CPU手册》《元器件选型手册》五个分册。在开始专栏的更新前,博主先列出专栏的大纲,以供大家参考。大家直接点击大纲中的蓝色标题即可轻松传送。

fydar的博客 5890

ios屏幕旋转

旧项目在iOS6中无法旋转的解决办法 之前做的一个iPad上的app,在最新的sdk下重新编译,出现无法旋转的情况。查看了一些文档,由于iOS6在旋转处理的api有了变化,之前处理旋转的函数shouldAutorotateToInterfaceOrientation:在iOS6下无效,由supportedInterfaceOrientations 和 shouldAutorotate替代

zrhloveswallow的专栏 1785

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统) .

转自:http://blog.csdn.net/cococoolwhj/article/details/8208991 概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToI

iOS开发专栏 1198

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

IOS6屏幕旋转问题总结 .

概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToInterfaceOrientation方法。 但是iOS 6里屏幕旋转改变了很多,之前的 shouldAutorotat

_听雨眠的专栏 1082

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

iOS6以上屏幕旋转详解

屏幕旋转的研究理由: 因为本人从事视频类的iOS开发工作,经常项目中经常会遇到需要在不同的页面对屏幕方向进行控制,例如正常的列表页面都只支持竖屏不能旋转,而播放页面需要能够控制旋转 : - 手动点击全屏进入全屏并保持全屏不自动旋转; - 旋转屏幕能够屏幕能够自动旋转。 相信很多人也在屏幕旋转上遇到过不同的疑惑与阻碍,下面介绍实现方式,以及遇到的坑。 屏幕旋转基础 我们能

猪猪的思维有点长的博客 1118

问题解决:iOS6下shouldAutorotateToInterfaceOrientation不起作用,屏幕旋转同时支持iOS5和iOS6

在iOS6下shouldAutorotateToInterfaceOrientation被弃用,现在iOS6下有三个新方法处理屏幕旋转: // 是否支持屏幕旋转 - (BOOL)shouldAutorotate { return YES; } // 支持的旋转方向 - (NSUInteger)supportedInterfaceOrientations { return UI

bluesLf的专栏 8963

为什么IOS6屏幕无法旋转?

这篇为原创加转载。。。。 在网上看了很多关于IOS6屏幕旋转的帖子,说的基本都一样,主要在于两个方法的调用和一个地方的设置: 两个方法: -(NSUInteger)supportedInterfaceOrientations{     NSLog(@"exe the supportedInterfaceOrientations.......");     return UIInter

NightWish 1461

UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例)  和 IOS6屏幕旋转详解

1. UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法 (实例) 博客分类:  IOS / Objective-C UIDeviceOrientation      是机器硬件的当前旋转方向   这个你只能取值 不能设置 UIInterfaceOrientation   是你程序界面的当前旋转方向

qq515383106的专栏 8637

UIInterfaceOrientation 设备旋转的用法 (实例) 和 IOS6屏幕旋转详解

概述: 在iOS6之前的版本中,通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个viewController支持旋转,只需要重写shouldAutorotateToInterfaceOrientation方法。 但是iOS 6里屏幕旋转改变了很多,之前的 shouldAutorotat

pilqc2009的专栏 4701

ios6,7适配旋转

知识点: *UIViewController的shouldAutorotateToInterfaceOrientation方法被deprecated。在ios6里,是使用supportedInterfaceOrientations and shouldAutorotate 2个方法来代替shouldAutorotateToInterfaceOrientation。注意:为了向后兼容iOS 4

taylor的专栏 4490

iOS 5.1及6.0 屏幕旋转的兼容问题

iOS 5.1及6.0 屏幕旋转的兼容问题: 在iOS6.0以前,由各个view的控制器(即viewController)使用各自的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;来控制view的旋转。但在iOS6.0中,将此方法废弃掉了:见官方文档说明:

wohaoxuexi的专栏 2843

iOS6屏幕旋转

苹果将sdk从5.1升级到6.0之后在屏幕旋转的支持上做了一些修改。需要注意的为以下3点: 1 plist文件:首先必须在plist文件中Supported interface orientations项进行对应方向的支持。iphone和ipad分别为两项。如下图 2 新增加的关于旋转支持的函数: 需要在rootviewcontroller中响应以下2个方法:

justinjing的专栏 2777

iOS6下关于屏幕旋转的控制

之前做了一个应用,但由于整应用界面个都是竖屏,不允许横屏,所以一直没有关注这个,昨天开发一个图片预览的类库(类似系统的查看图片),其中一个特性当然需要支持横屏,所以就压找了一下资料,之前已经听闻在屏幕控制上,iOS6上有了比较坑爹的变化。比如,让视频支持正常坚屏和两种横屏,兼容的做法是: 1 2 3 4 5 6 7 8 9 10 11 12 13

把握自己。 3745
上一篇: 关于UIWebView一个很奇怪问题的另类解决办法(高度递增问题)
下一篇: 查找iOS项目中是否使用了UDID
sing_sing
博客等级 码龄20年 209粉丝 66原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址