貌似算是一个iOS的bug,很头疼
2013-07-09 17:17
387 查看
iOS 6 版本之后屏幕旋转方法发生了变化,一不小心陷入了一个坑里,头疼了半天没找到原因,找到原因之后一顿唉声叹气。。。。貌似算是iOS一个不合理的bug.
要兼容iOS5和iOS6屏幕旋转应该这样写:
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
- (BOOL)shouldAutorotate
{
return
YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice
currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPhone) {
return
UIInterfaceOrientationMaskAllButUpsideDown;
}else{
return
UIInterfaceOrientationMaskLandscape;
}
}
#endif
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice
currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPhone) {
return interfaceOrientation !=
UIInterfaceOrientationPortraitUpsideDown;
}else{
return (interfaceOrientation ==
UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==
UIInterfaceOrientationLandscapeRight);
}
}
这样写在ipad, iphone上ios5和ios6版本都是没有问题的。可关键的是习惯了if else写法,如果写成如下方式就痛苦了。。。
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
- (BOOL)shouldAutorotate
{
return
YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice
currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPhone) {
return
UIInterfaceOrientationMaskAllButUpsideDown;
}else{
return
UIInterfaceOrientationMaskLandscape;
}
}
#else //这个else在ios5版本上是跑不进来的
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom]
== UIUserInterfaceIdiomPhone) {
return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}else{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==UIInterfaceOrientationLandscapeRight);
}
}
#endif
我到觉得这算是一个ios不合理的方法。
如果大家有好的方式或者解释文档,请在评论里给出答案,以解答我的疑惑。。。感谢大家
要兼容iOS5和iOS6屏幕旋转应该这样写:
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
- (BOOL)shouldAutorotate
{
return
YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice
currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPhone) {
return
UIInterfaceOrientationMaskAllButUpsideDown;
}else{
return
UIInterfaceOrientationMaskLandscape;
}
}
#endif
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice
currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPhone) {
return interfaceOrientation !=
UIInterfaceOrientationPortraitUpsideDown;
}else{
return (interfaceOrientation ==
UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==
UIInterfaceOrientationLandscapeRight);
}
}
这样写在ipad, iphone上ios5和ios6版本都是没有问题的。可关键的是习惯了if else写法,如果写成如下方式就痛苦了。。。
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_5_1
- (BOOL)shouldAutorotate
{
return
YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice
currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPhone) {
return
UIInterfaceOrientationMaskAllButUpsideDown;
}else{
return
UIInterfaceOrientationMaskLandscape;
}
}
#else //这个else在ios5版本上是跑不进来的
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom]
== UIUserInterfaceIdiomPhone) {
return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}else{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==UIInterfaceOrientationLandscapeRight);
}
}
#endif
我到觉得这算是一个ios不合理的方法。
如果大家有好的方式或者解释文档,请在评论里给出答案,以解答我的疑惑。。。感谢大家
相关文章推荐
- IOS-OC 当时接受一个烂尾的项目遇到的bug 内存泄漏 运行时的闪退,无法定位
- IOS学习笔记(12)——一个模态视图切换bug引发的思考
- IOS开发笔记之二十九——一个野指针引起的bug
- 这算是ASP.NET MVC的一个大BUG吗?
- 一个iOS bug引发的思考
- MySQL JDBC 5.1.25的一个坑(应该算是BUG)
- 貌似是微软编译器的一个Bug
- Eclipse Luna WTP 与 Tomcat 8 的整合存在一个很头疼的 Bug
- 貌似是chrome在ubuntu下的一个bug
- 应该算是WebFormView的一个Bug
- iOS 10系统的一个严重Bug
- iOS开发之使用UICollectionView实现美团App的分类功能【偶现大众点评App的一个小bug】
- iOS layoutMargins 的坑:一个活久见的 bug
- IOS开发笔记之十一——一个delegate没有更新引起的bug(bug总结三)
- iOS开发笔记之三十一——日历NSCaledar使用过程中遇到的一个苹果系统bug
- 这算是VC6.0编译器的一个Bug么?
- 应该算是WebFormView的一个Bug
- 关于ios横竖屏显示不正常的一个Bug修复
- 某页游erlang服务端广播算法效率好差,应该算是一个bug了吧
- iOS layoutMargins 的坑:一个活久见的 bug