【问题标题】:ios portrait and landscape modeios纵向和横向模式
【发布时间】:2014-02-25 14:53:58
【问题描述】:

我有以下场景:

我从 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 的问题,虽然我已将其限制为纵向模式。我做错了什么?

【问题讨论】:

    标签: ios uinavigationcontroller landscape-portrait


    【解决方案1】:

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

    #import "UINavigationController+MyNavigation.h"
    
    @implementation UINavigationController (MyNavigation)
    
    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
    }
    

    这解决了我的问题。

    【讨论】:

    • 它没有解决我的问题。我的视图仍然可以在横向和纵向模式下旋转
    • 我确实评论了方法 shouldAutorotateToInterfaceOrientation。
    • 你的意思是评论 shouldAutoRotate 解决了你的问题?
    • 是的,我做到了。我刚才意识到的是方法:shouldAutoriatte、shouldAutorotateToInterfaceOrientation 或supportedInterfaceOrientatin 没有被调用。你知道为什么吗?我有一个 tabBarController,其中包含第一个 viewController,它应该只能是纵向的,而不是从这个 firstViewController 我按下一个按钮,它将我发送到应该处于纵向和横向模式的第二个 viewController
    • 很明显你没有实现我上面回答的那个类。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多