在ios10中,不推荐使用setStatusBarOrientation。旧项目代码的一些片段无法正常工作。那么如何解决呢?以下代码将根据需要更改viewcontroller:
float angle;
CGRect rect;
// UIInterfaceOrientation orientation;
float fWidth = _viewController.view.bounds.size.width;
float fHeight = _viewController.view.bounds.size.height;
float fMaxValue = (fWidth > fHeight) ? fWidth : fHeight;
float fMinValue = (fWidth > fHeight) ? fHeight : fWidth;
if ((eScreenOrientation)ore == eScreenOrientation::Landscape) {
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) {
// orientation = UIInterfaceOrientationLandscapeRight;
angle = M_PI_2;
} else {
// orientation = UIInterfaceOrientationLandscapeLeft;
angle = -M_PI_2;
}
rect = CGRectMake(0, 0, fMaxValue, fMinValue);
} else {
// orientation = UIInterfaceOrientationPortrait;
angle = 0;
rect = CGRectMake(0, 0, fMinValue, fMaxValue);
}
// [[UIApplication sharedApplication] setStatusBarOrientation: orientation];
_viewController.view.transform = CGAffineTransformMakeRotation(angle);
_viewController.view.bounds = rect;
[_viewController resetViewSize];
答案 0 :(得分:1)
可以认为 - [UIApplication statusBarOrientation]已被弃用,以支持使用UITraitCollection和大小类。
同样来自apple docs
@property(readonly,nonatomic)UIInterfaceOrientation statusBarOrientation __TVOS_PROHIBITED;
//在iOS 6.0及更高版本中,状态栏方向的显式设置更受限制。 @property(readwrite,nonatomic)UIInterfaceOrientation statusBarOrientation NS_DEPRECATED_IOS(2_0,9_0, “在iOS 6.0及更高版本中,状态栏方向的显式设置更受限制”)__ TVOS_PROHIBITED;
似乎你不能将上述代码用于同一目的。
可能是此链接可以帮助您Link to orientation