您的位置:首页 > 移动开发 > IOS开发

貌似算是一个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不合理的方法。
如果大家有好的方式或者解释文档,请在评论里给出答案,以解答我的疑惑。。。感谢大家
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: