ios - 不推荐使用 setStatusBarOrientation,如何在 ios10 中更改设备方向
<p><p>在 ios10 中,不推荐使用 setStatusBarOrientation。旧项目代码的某些片段无法正常工作。那么如何解决它们呢?以下代码将根据需要更改 ViewController :</p>
<pre><code> 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 ([ 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);
}
//[ setStatusBarOrientation: orientation];
_viewController.view.transform = CGAffineTransformMakeRotation(angle);
_viewController.view.bounds = rect;
;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>相信 - 已被弃用以支持使用 UITraitCollection 和大小类。</p>
<p>同样来自苹果文档</p>
<p>@property(readonly, nonatomic) UIInterfaceOrientation statusBarOrientation __TVOS_PROHIBITED;</p>
<p>//状态栏方向的显式设置在 iOS 6.0 及更高版本中受到更多限制。
@property(readwrite, nonatomic) UIInterfaceOrientation statusBarOrientation NS_DEPRECATED_IOS(2_0, 9_0,
"在 iOS 6.0 及更高版本中,状态栏方向的显式设置受到更多限制") __TVOS_PROHIBITED;</p>
<p>看来您不能将上述代码用于相同目的。</p>
<p>也许这个链接可以帮助你 <a href="https://stackoverflow.com/questions/25238620/ios-8-rotation-methods-deprecation-backwards-compatibility/26132456#26132456" rel="noreferrer noopener nofollow">Link to orientation
</a> </p></p>
<p style="font-size: 20px;">关于ios - 不推荐使用 setStatusBarOrientation,如何在 ios10 中更改设备方向,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45099819/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45099819/
</a>
</p>
页:
[1]