【问题标题】:how to change screen orientation on new modal view controller iOS如何在新的模态视图控制器 iOS 上更改屏幕方向
【发布时间】:2013-09-09 21:22:06
【问题描述】:

我有一个使用 Xcode 为 iPhone 开发的应用程序,它在激活旋转的情况下以纵向模式显示我的视图控制器。

我的表格视图中有一个单元格在模态模式下触发了一个新的视图控制器 (iPhoneSignVC),我的问题是......

有没有办法从一开始就确定我的新模态视图控制器的方向?我的意思是...我希望我的新视图控制器处于横向模式,并且在该特定视图控制器上没有激活屏幕旋转功能

到目前为止,我所做的是创建一个覆盖 UINavigation 控制器类的新类

#import "UINavigationController.h"
#import "iPhoneSignVC.h"

@implementation UINavigationController (overrides)

- (BOOL)shouldAutorotate
{
    id currentViewController = self.topViewController;

    if ([currentViewController isKindOfClass:[iPhoneSignVC class]])
        return NO;


    return YES;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    id currentViewController = self.topViewController;

    if ([currentViewController isKindOfClass:[iPhoneSignVC class]]){
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }

    return (interfaceOrientation == UIInterfaceOrientationMaskAll);
}


@end

我试过这个没有成功...

提前感谢大家的支持

【问题讨论】:

    标签: ios xcode orientation


    【解决方案1】:

    我想这就是您的模态视图以您想要的方向打开所需的全部内容:

    #import "UINavigationController.h"
    #import "iPhoneSignVC.h"
    
    
    @implementation UINavigationController (overrides)
    
    - (NSUInteger)supportedInterfaceOrientations {
    
        if ([self.topViewController isKindOfClass:[iPhoneSignVC class]])
            return UIInterfaceOrientationMaskLandscape;
    
        return UIInterfaceOrientationMaskAll;
    }
    @end
    

    【讨论】:

      【解决方案2】:

      根据底层操作系统,有多种考虑因素。 看看这个very comprehensive questionthis solution

      【讨论】:

      • 您发布了一个问题的链接,接受的答案是更多链接。尝试发布答案而不是链接,就好像链接改变了,那么答案就没用了
      猜你喜欢
      • 1970-01-01
      • 2016-02-27
      • 2015-03-05
      • 2014-08-27
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      相关资源
      最近更新 更多