VC旋转设置:
- (void)viewDidLoad {
[super viewDidLoad];
[UIApplication sharedApplication].statusBarHidden = YES;
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
webViewWidth = MainScreenWidth;
webViewHeight = MainScreenHeight;
} else {
webViewWidth = MainScreenHeight;
webViewHeight = MainScreenWidth;
}
} else {
webViewWidth = MainScreenWidth;
webViewHeight = MainScreenHeight;
}
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
}
//隐藏状态栏
- (BOOL)prefersStatusBarHidden{
return YES;
}
//横竖屏
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsPortrait(orientation)) {
// 如果状态栏竖着的,不支持controller的旋转
return NO;
} else if (UIInterfaceOrientationIsLandscape(orientation)) {
return YES;
}
return NO;
}
// 第二个方法直接返回支持的旋转方向,该方法在iPad上的默认返回值是UIInterfaceOrientationMaskAll,iPhone上的默认返回值是UIInterfaceOrientationMaskAllButUpsideDown
- (NSUInteger)supportedInterfaceOrientations {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
抱歉啊,忘记这个帖子了。。
使用VC旋转通过statusBarOrientation的方向判断旋转方向,
webView是我创建的一个满屏的控件
在iOS8之前横屏后,屏幕的宽和高的数值是对换了(即宽变成了高,高变成了宽),
但在iOS8之后宽高并没有对换,所以在iOS8之后旋转横屏如果不改变宽高的话就会造成屏幕一侧为空的情况.
代码是之前写的了,可能会有些乱。。。