菜鸟教程小白 发表于 2022-12-11 16:59:09

ios - 旋转行为 iOS8 vs iOS9


                                            <p><p>我有一个应用程序在所有 View 中都锁定为纵向,但 AllButUpsideDown 除外。我使用的方法是在目标常规设置菜单中启用纵向、横向左侧和横向右侧。然后有 UINavigationController 和 UITabBarController 的子类覆盖 <code>func supportedInterfaceOrientations() -> UIInterfaceOrientationMask</code> 并返回 <code>.Portrait</code>。</p>

<p>然后在需要能够旋转的 ViewController 中,我还覆盖了 <code>func supportedInterfaceOrientations() -> UIInterfaceOrientationMask</code> 并返回 <code>.AllButUpsideDown</code>。这很好用,因为此 ViewController 仅作为模式呈现,即 <code>aViewController.presentViewController()</code>.</p>

<p>所有这些工作在 iOS8 上的 iOS9 上都按预期工作,但是如果我在横向时关闭可旋转 ViewController ,UI 将被缩放为横向,尽管它会以纵向显示。</p>

<p> <a href="/image/tfnix.png" rel="noreferrer noopener nofollow"><img src="/image/tfnix.png" alt="result in iOS8"/></a> </p>

<p>有人知道该怎么办吗?我从一开始就错误地处理这个轮换问题吗?任何干净的修复?解决方法?黑客?</p>

<p><strong>更新</strong></p>

<p>我的问题源于我使用自定义转换来呈现和关闭可以旋转的 ViewController 。我试图用一堆不同的解决方案来解决它一段时间。我最接近的解决方案是为我的可旋转 ViewController 使用单独的 UIWindow,除了载体栏仍然处于错误方向的问题之外,它可以工作,这是我无法解决的问题。</p>

<p>我采用的解决方案(不是真正的解决方案)是仅在 iOS9+ 中使用自定义过渡,而在 iOS8 上使用默认的当前过渡。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>当我从 VC 导航回来时,我遇到了类似的问题,它支持横向到只有纵向的。我没有找到一个干净的解决方法。不建议使用这几行,但如果您迫不及待,可以在即将关闭时强制您的设备方向。</p>

<pre><code>let value = UIInterfaceOrientation.Portrait.rawValue
UIDevice.currentDevice().setValue(value, forKey: &#34;orientation&#34;)
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 旋转行为 iOS8 vs iOS9,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/38368841/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/38368841/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 旋转行为 iOS8 vs iOS9