setStatusBarOrientation已弃用,如何在ios10中更改设备方向
在ios10中,不推荐使用SetStatusBaroOrientation。旧项目代码的某些片段无法正常工作。那么如何解决呢?以下代码将根据需要更改viewcontroller的设置:setStatusBarOrientation已弃用,如何在ios10中更改设备方向,ios,orientation,Ios,Orientation,在ios10中,不推荐使用SetStatusBaroOrientation。旧项目代码的某些片段无法正常工作。那么如何解决呢?以下代码将根据需要更改viewcontroller的设置: float angle; CGRect rect; // UIInterfaceOrientation orientation; float fWidth = _viewController.view.bounds.size.width; float fHeight = _viewCon
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];
可以相信,-[UIApplication statusBarOrientation]已被弃用以支持UITraitCollection和size类的使用 同样来自苹果文档 @属性(只读、非原子)UIInterface定向状态禁止定向 //在iOS 6.0及更高版本中,状态栏方向的显式设置受到更多限制。 @属性(读写,非原子)UIInterfaceOrientation状态BarOrientation NS\u不推荐的IOS(2\u 0,9\u 0, “在iOS 6.0及更高版本中,状态栏方向的显式设置受到更多限制”)\uuuuTVOS\u禁止 似乎您不能将上述代码用于相同的目的 也许这个链接对你有帮助