ios肖像和风景模式

时间:2014-02-25 14:53:58

标签: ios uinavigationcontroller landscape-portrait

我有以下情况:

从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;
}

firstViewController推送另一个视图控制器,它需要具有纵向和横向功能。

secondViewController按预期行事 - 在肖像和横向模式

我遇到了以横向模式显示的firstViewController问题,虽然我已将其限制为纵向模式。我做错了什么?

1 个答案:

答案 0 :(得分:1)

在项目中使用以下方法添加 UINavigationController类别

#import "UINavigationController+MyNavigation.h"

@implementation UINavigationController (MyNavigation)

-(BOOL)shouldAutorotate
{
    return YES;
}

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

这解决了我的问题。