IOS 6的自动旋转问题

IOS 6的自动旋转问题,第1张

概述iOS 6的rotation改变了很多。先来看看官方的描述  http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/ 知识点: *UIViewController的shouldAutorotateToInterfaceOrientation方法被deprecated。在ios6里,是使用supportedInterf

iOS 6的rotation改变了很多。先来看看官方的描述  http://www.bgr.com/2012/08/06/ios-6-beta-4-change-log-now-available/


知识点:

*UIVIEwController的shouldautorotatetoInterfaceOrIEntation方法被deprecated。在ios6里,是使用supportedInterfaceOrIEntations and shouldautorotate 2个方法来代替shouldautorotatetoInterfaceOrIEntation。注意:为了向后兼容iOS 4 and 5,还是需要在你的app里保留shouldautorotatetoInterfaceOrIEntation。

for ios 4 and 5,如果没有重写shouldautorotatetoInterfaceOrIEntation,那么对于iphone来讲,by default是只支持portrait,不能旋转

for ios 6,如果没有重写shouldautorotate and supportedInterfaceOrIEntations,by default,iphone则是"可以旋转,支持非upsIDe down的方向",而ipad是"可以选择,支持所有方向"


example 1: for ios 4 and 5,iphone device,若要"可以旋转,支持非upsIDe down的方向",则可以在vIEw controller里

[cpp]  view plain copy - (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation {   return (interfaceOrIEntation != UIDeviceOrIEntationPortraitUpsIDeDown);   }  
example 2: for ios 6,若要“不能旋转,只支持portait",则可以在vIEw controller里

copy BOol)shouldautorotate   {       return NO;   }  
example 3: for ios 6,ipad device,若要“可以旋转,只支持landscape",则可以在vIEw controller里
copy -(NSUInteger)supportedInterfaceOrIEntations{       return UIInterfaceOrIEntationMaskLandscape;   }      - (return YES;  
* 在iOS 4 and 5,都是由具体的vIEw controller来决定对应的vIEw的orIEntation设置。而在iOS 6,则是由top-most  controller来决定vIEw的orIEntation设置。

举个例子:你的app的rootVIEwController是navigation controller "nav",在”nav"里的stack依次是:main vIEw -> sub vIEw > sub sub vIEw,而main vIEw里有一个button会present modal vIEw "modal vIEw".

那么for ios 4 and 5,在ipad里,如果你要上述vIEw都仅支持横屏orIEntation,你需要在上面的main vIEw,sub vIEw,sub sub vIEw,model vIEw里都添加

copy return (interfaceOrIEntation == UIInterfaceOrIEntationLandscapeleft || interfaceOrIEntation==UIInterfaceOrIEntationLandscapeRight);   而对于iOS6,由于是由top-most controller来设置orIEntation,因此你在main vIEw,sub sub vIEw里添加下面的代码是没有任何效果的,而应该是在nav controller里添加下列代码。而modal vIEw则不是在nav container里,因此你也需要在modal vIEw里也添加下列代码。

copy 注意:

*你需要自定义一个UINavigationController的子类for "nav controller",这样才可以添加上述代码。

* 和navigation controller类似,tab controller里的各个vIEw的orIEntation设置应该放在tab controller里

for ios6的top-most controller决定orIEntation设置,导致这样一个问题:在 top-most controller里的vIEws无法拥有不相同的orIEntation设置。例如:for iphone,在nav controller里,你有main vIEw,sub vIEw and sub sub vIEw,前2个都只能打竖,而sub sub vIEw是用来播放vIDeo,可以打横打竖。那么在ios 4 and 5里可以通过在main vIEw and sub vIEw的shouldautorotatetoInterfaceOrIEntation里设置只能打竖,而在sub sub vIEw的shouldautorotatetoInterfaceOrIEntation设置打竖打横即可。而在ios 6里则无法实现这种效果,因为在main vIEw,sub vIEw and sub sub vIEw的orIEntation设置是无效的,只能够在nav controller里设置。那么你可能想着用下列代码在nav controller里控制哪个vIEw打竖,哪个vIEw打横

copy if([[self topVIEwController] isKindOfClass:[SubSubVIEw class]])           return UIInterfaceOrIEntationMaskAllButUpsIDeDown;   else   return UIInterfaceOrIEntationMaskPortrait;   是的,这样可以使得在main vIEw and sub vIEw里无法打横,而sub sub vIEw横竖都行。但问题来了,如果在sub sub vIEw时打横,然后back to sub vIEw,那么sub vIEw是打横显示的!

目前想到的解决方法只能是把sub sub vIEw脱离nav controller,以modal vIEw方式来显示。这样就可以在modal vIEw里设置打横打竖,而在nav controller里设置只打竖。

* 说了那么多,其实如果你的app的所有vIEw的orIEntation的设置是统一的,那么你可以简单的在pList file里设置即可,不用添加上面的代码。而如果你添加了上面的代码,就会覆盖pList里orIEntation的设置。

* in iOS 6,当vIEw controller present时,不会call willRotatetoInterfaceOrIEntation:duration:,willAnimateRotationToInterfaceOrIEntation:duration:,and dIDRotateFromInterfaceOrIEntation: methods,只有在发生rotate的时候才会call

总结

以上是内存溢出为你收集整理的IOS 6的自动旋转问题全部内容,希望文章能够帮你解决IOS 6的自动旋转问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1089512.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存