菜鸟教程小白 发表于 2022-12-13 06:28:18

ios - UINavigationController supportInterfaceOrientations : category vs swizzle


                                            <p><p>我在我的 iPhone 应用程序中使用带有多个 UINavigationControllers 的 tabBarController,现在我想添加对旋转的支持(在某些 ViewController 上,不是全部)。我知道我需要为我的 UIViewControllers 实现 supportedInterfaceOrientation 方法。</p>

<p>当设备旋转时,在 UINavigationController 上调用了 supportedInterfaceOrientation,但我需要在我的 viewControllers 上调用它。最好的方法是什么?</p>

<ul>
<li><p>我看到有些人在 UINavigationController 上创建了一个类别,它覆盖了supportedInterfaceOrientation 来查询 subviewController 。但我知道 Apple 不赞成使用类别来覆盖方法。 (我已经这样实现了,它运行良好,但我想确保该应用继续与 future 版本的 iOS 一起使用。)</p></li>
<li><p>使用method swizzling怎么样?</p></li>
<li><p>子类 UINavigationController?</p></li>
</ul>

<p>任何建议表示赞赏。 :)</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您使用 <em>iOS 6+</em>,我建议继承 <code>UINavigationController</code> 并覆盖 <code>supportedInterfaceOrientations</code></p>

<p>类似于:</p>

<pre><code>- (NSUInteger)supportedInterfaceOrientations;
{
return ;
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UINavigationController supportInterfaceOrientations : category vs swizzle,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/21866880/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/21866880/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UINavigationController supportInterfaceOrientations : category vs swizzle