我有以下情景:

从appdelegate我做:

firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController];
.

firstviewcontroller - 需要只在纵向模式

为了完成这个我做了:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
   return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate
{
   return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
   return UIInterfaceOrientationMaskPortrait;
}
.

from firstViewController i我按另一个视图控制器,需要具有纵向和横向功能。

secondViewController按预期作用 - 在portait和横向模式下

我有FirstViewController的问题,也以横向模式显示,虽然我将其限制为纵向模式。我做错了什么?

有帮助吗?

解决方案

在项目中添加 uinavigationController类别

#import "UINavigationController+MyNavigation.h"

@implementation UINavigationController (MyNavigation)

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
.

这个解决了我的问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top