ios纵向和横向模式
<p><p>我有以下场景:</p>
<p>我从 appDelegate 做:</p>
<pre><code>firstViewController = [ initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *firstNavController = [initWithRootViewController:firstViewController];
</code></pre>
<p>firstViewController - <strong>只需要在纵向模式下</strong></p>
<p>为了做到这一点,我做了:</p>
<pre><code>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
</code></pre>
<p>从 <code>firstViewController</code> 我正在<strong>插入另一个 ViewController </strong>,它需要同时具有纵向和横向功能。</p>
<p><code>secondViewController</code> 按预期运行 - 在纵向和横向模式下</p>
<p><strong>我也遇到了在横向模式下显示的 firstViewController 的问题,</strong>虽然我已将其限制为纵向模式。我做错了什么?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在您的项目中使用以下方法添加 <strong>UINavigationController 类别</strong></p>
<pre><code>#import "UINavigationController+MyNavigation.h"
@implementation UINavigationController (MyNavigation)
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
</code></pre>
<p>这解决了我的问题。 </p></p>
<p style="font-size: 20px;">关于ios纵向和横向模式,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/22017786/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/22017786/
</a>
</p>
页:
[1]