菜鸟教程小白 发表于 2022-12-12 22:56:51

ios - 当 View 从纵向更改为横向时,方向不会改变


                                            <p><p>我有仅纵向的菜单和可以是纵向或横向的详细 View (带有 <code>UIWebView</code>)。</p>

<p>当我进入详细 View 并旋转设备横向并以这种方式从该屏幕返回到仅应为纵向的菜单时,菜单处于横向(以及状态栏和导航栏)。</p>

<p>有没有办法避免这种情况并强制将屏幕旋转到所需(支持的)方向?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>@kkumpavat 提出的解决方案对我不起作用,或者不够清楚,我无法理解。我做了更多搜索并找到了使用的解决方案:</p>

<pre><code>    // http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation
    // http://openradar.appspot.com/radar?id=697
    [ performSelector:NSSelectorFromString(@&#34;setOrientation:&#34;)
                                 withObject:UIInterfaceOrientationPortrait];
</code></pre>

<p>但这会产生烦人的警告,我已将其替换为:</p>

<pre><code>//force update of screen orientation
if (self.interfaceOrientation != ) {
    [ setValue:]
                              forKey:@&#34;orientation&#34;];
}
</code></pre>

<p>从 NavigationController 的 <code>viewDidAppear</code> 调用。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 当 View 从纵向更改为横向时,方向不会改变,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/24141449/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/24141449/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 当 View 从纵向更改为横向时,方向不会改变