启动屏幕之后的视图需要以设备的方向显示,但一旦显示就不应自动旋转到其他方向。我用了这段代码:
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
return YES;
}
-(UIInterfaceOrientationMask) supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
return UIInterfaceOrientationMaskAll;
}
这适用于iPad但在iPhone中,为shouldAutorotate设置NO会导致仅限肖像。这是正常的行为吗?如果是这样的话,如果不在iPhone中进行自动旋转,如何仅为特定的视图控制器支持所有方向?
答案 0 :(得分:0)
启动时需要检测设备的方向:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
将其转换为界面方向:
switch (orientation) {
case UIDeviceOrientationLandscapeRight:
return UIInterfaceOrientationLandscapeLeft;
default:
return UIInterfaceOrientationLandscapeRight;
}
现在将其存储在某个地方以进行全局访问并返回:
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
return globalOrientation;
}