【问题标题】:Force Landscape ViewController in iOS 7iOS 7 中的强制景观 ViewController
【发布时间】:2014-04-24 20:48:36
【问题描述】:

我有十多个处于纵向模式的 ViewController,但无论设备的方向如何,我都需要强制一个处于横向模式。

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    解决办法如下:

    1) 将 LandscapeViewController 嵌入到子类 NavigationController 中,并使用 modal segue 从 PortraitViewController 连接它。

    2) 子类 UINavigationController

    LandscapeNavigationController.m

    -(BOOL)shouldAutorotate
    {
        return NO;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscapeLeft;
    }
    

    3) 不要忘记关闭你的模态 VC(在这种情况下是从我的 Bar Buttom Item Action 开始)

    - (IBAction)goBack:(id)sender
    {
        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    }
    

    【讨论】:

    • 使用这样的类别是一个糟糕的想法——它在碰撞时会发生什么没有记录的行为。在使用类别时,您应该始终为方法添加前缀以避免这种情况。在这种情况下子类化导航控制器将是一个更好的解决方案。
    • 你是对的@OliverAtkinson。我正在用你的方法改变我的解决方案。我正在编辑我的答案
    • 这些类别的重点是覆盖。但我会选择一个子类。
    • 如何以编程方式执行此操作?
    • 谢谢@FedeCugliandolo ..我没有使用带有纵向模式的单独的子类 NavigationController,它起作用了 ;)..
    猜你喜欢
    • 2013-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多