setStatusBarOrientation 已弃用,如何在 ios10 中更改设备方向
setStatusBarOrientation deprecated,how to change the device orientation in ios10
在 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];
据信 -[UIApplication statusBarOrientation] 已被弃用以支持使用 UITraitCollection 和大小 类。
同样来自苹果文档
@属性(只读,非原子)UIInterfaceOrientation statusBarOrientation __TVOS_PROHIBITED;
// 状态栏方向的显式设置在 iOS 6.0 及更高版本中受到更多限制。
@属性(读写,非原子)UIInterfaceOrientation statusBarOrientation NS_DEPRECATED_IOS(2_0, 9_0,
"Explicit setting of the status bar orientation is more limited in iOS 6.0 and later") __TVOS_PROHIBITED;
看来您不能将上述代码用于相同目的。
可能这个link可以帮助你Link定位
在 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];
据信 -[UIApplication statusBarOrientation] 已被弃用以支持使用 UITraitCollection 和大小 类。
同样来自苹果文档
@属性(只读,非原子)UIInterfaceOrientation statusBarOrientation __TVOS_PROHIBITED;
// 状态栏方向的显式设置在 iOS 6.0 及更高版本中受到更多限制。 @属性(读写,非原子)UIInterfaceOrientation statusBarOrientation NS_DEPRECATED_IOS(2_0, 9_0, "Explicit setting of the status bar orientation is more limited in iOS 6.0 and later") __TVOS_PROHIBITED;
看来您不能将上述代码用于相同目的。
可能这个link可以帮助你Link定位