iOS8之后的屏幕旋转和iOS6,7有很大不同,项目中自己之前遇到过这样的需求,从A界面呈现B界面,如果A横屏则呈现出的B也为横屏,如果A竖屏则呈现出的B也为竖屏,实现代码如下:
//当前屏幕高度
#define MainScreenHeight [UIScreen mainScreen].bounds.size.height
//当前屏幕宽度
#define MainScreenWidth [UIScreen mainScreen].bounds.size.width
//webView是当前满屏的控件
- (void)viewDidLoad {
[super viewDidLoad];[UIApplication sharedApplication].statusBarHidden = YES;
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
if (UIInterfaceOrientationIsLandscape(orientation)) {
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
webViewWidth = MainScreenWidth;
webViewHeight = MainScreenHeight;
} else {
webViewWidth = MainScreenHeight;
webViewHeight = MainScreenWidth;
}
} else {
webViewWidth = MainScreenWidth;
webViewHeight = MainScreenHeight;
}
}
- (BOOL)prefersStatusBarHidden{
return YES;
}
//设置是否支持旋转
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsPortrait(orientation)) {
// 如果状态栏竖着的,不支持controller的旋转
return NO;
} else if (UIInterfaceOrientationIsLandscape(orientation)) {
return YES;