首页 文章

从横向方向从iPhone 6 Plus主屏幕启动纵向导致错误的方向

提问于
浏览
58

这个问题的实际 Headers 比我可能适合的长:

启动一个应用程序,其根视图控制器仅支持纵向方向,但在主屏幕处于横向方向时支持iPhone 6 Plus上的横向方向会导致应用程序窗口处于横向方向但设备为在纵向方向 .

简而言之,它看起来像这样:

当它看起来像这样:

Steps to Reproduce:

  • 运行iOS 8.0的iPhone 6 Plus .

  • 一个应用程序,其plist支持所有但纵向倒置的方向 .

  • 应用程序的根视图控制器是UITabBarController .

  • Everything,标签栏控制器及其所有后代子视图控制器从 supportedInterfaceOrientations 返回 UIInterfaceOrientationMaskPortrait .

  • 从iOS主屏幕开始 .

  • 旋转到横向(需要iPhone 6 Plus) .

  • 冷启动应用程序 .

  • 结果:界面方向损坏 .

除了完全禁用横向之外,我无法想到强制执行纵向定位的任何其他方式,这是我无法做到的:我们的网络浏览器模态视图控制器需要横向 .

我甚至尝试了子类化UITabBarController并重写supportedInterfaceOrientations以返回仅限纵向的掩码,但是这(即使使用上述所有其他步骤)也没有解决问题 .


Here's a link to a sample project showing the bug.


13 回答

  • 2

    只需调用[application setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];在app delegate方法 - (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    实际上设备现在是启动后的UIInterfaceOrientationPortrait,如果你触摸一个inputField,键盘是纵向布局

  • 38

    在iPhone 6 Plus上以横向方式启动我们的应用程序时遇到了同样的问题 .

    我们的修复是通过项目设置从plist中删除横向支持的界面方向:

    Removed landscape orientation

    并实现应用程序:supportedInterfaceOrientationsForWindow:在app delegate中:

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    

    显然,plist中的信息是指定允许您的应用启动的方向 .

  • 5

    设置 UIApplicationstatusBarOrientation 似乎对我有用 . 我将它放在app委托中的 application:didFinishLaunchingWithOptions: 方法中 .

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        application.statusBarOrientation = UIInterfaceOrientationPortrait;
    
        // the rest of the method
    }
    
  • 0

    当使用UITabBarController作为根视图控制器时,这似乎是iOS 8中的一个错误 . 解决方法是使用大多数香草UIViewController作为根视图控制器 . 此vanilla视图控制器将用作选项卡栏控制器的父视图控制器:

    ///------------------------
    /// Portrait-Only Container
    ///------------------------
    
    @interface PortraitOnlyContainerViewController : UIViewController
    
    @end
    
    @implementation PortraitOnlyContainerViewController
    
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    @end
    
    // Elsewhere, in app did finish launching ...
    
    PortraitOnlyContainerViewController *container = nil;
    
    container = [[PortraitOnlyContainerViewController alloc] 
                  initWithNibName:nil 
                  bundle:nil];
    
    [container addChildViewController:self.tabBarController];
    self.tabBarController.view.frame = container.view.bounds;
    [container.view addSubview:self.tabBarController.view];
    [self.tabBarController didMoveToParentViewController:container];
    
    [self.window setRootViewController:container];
    
  • 0

    我有一个非常类似的问题 . 除了播放视频外,我想在任何地方强制使用肖像模式 .

    我做的是:

    1)在AppDelegate中强制app方向为纵向:

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        if ([window.rootViewController.presentedViewController isKindOfClass:[MPMoviePlayerViewController class]])
        {
            return UIInterfaceOrientationMaskAll;
        }
        return UIInterfaceOrientationMaskPortrait;
    }
    

    2)启动一个空的模态视图控制器修复了我的问题 . 我在第一个视图控制器的viewDidLoad中启动它,它位于我的NavigationViewController的根目录(应用程序启动后可见的第一个视图控制器):

    - (void)showAndHideNamelessViewControllerToFixOrientation {
        UIViewController* viewController = [[UIViewController alloc] init];
        [self presentViewController:viewController animated:NO completion:nil];
        [viewController dismissViewControllerAnimated:NO completion:nil];
    }
    
  • -1

    请尝试以下代码 . 可能这个问题是由景观发射时的关键窗口大小引起的 .

    // in application:didFinishLaunchingWithOptions: ...
    
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    [self.window setFrame:[[UIScreen mainScreen] bounds]]; //<- ADD!!
    
  • 0

    Jared使用通用容器视图控制器解决方法对我没有好运 . 我've already subclassed tab bar controller with supportedInterfaceOrientations with no luck as well. Regardless of orientation of the 6+ after launch the tab bar'的窗口正在报告 frame = (0 0; 736 414)

    到目前为止,我发现的唯一解决方法是在makeKeyAndVisible之后强制窗口框架

    [self.window makeKeyAndVisible]; self.window.frame = CGRectMake(0, 0, MIN(CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame)), MAX(CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame)));

  • 1

    我只希望我的应用程序以横向模式打开(并且没有在iPhone 6 Plus上显示您在上面描述的问题),所以我将 Landscape (left home button)Landscape (right home button) 设置为我的应用程序的PLIST文件中允许的唯一方向 . 这可以解决我的应用打开时的方向问题 . 但是,我需要我的应用程序仅支持一个视图的纵向模式,因为我在我的应用程序中显示 UIImagePickerController ,Apple需要在iPhone上以纵向模式显示 .

    通过在_888206中包含以下代码,我能够仅支持该视图的肖像,同时保持我的应用程序在横向模式下打开:

    -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    
            return UIInterfaceOrientationMaskAllButUpsideDown;
    
        } else {
    
            return UIInterfaceOrientationMaskAll;
    
        }
    
    }
    
  • 0

    我在我的应用程序上遇到了同样的错误,我用solution想出来了

    首先它没有用,但经过一些挖掘后我必须在启动画面后在初始控制器上进行 .

    答案是OjbC语言让我把它更新到Swift

    override var shouldAutorotate: Bool {
        return true
    }
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .portrait
    }
    

    不要忘记应该在初始视图控制器上 .

  • 1

    对于我自己,我遇到了与jaredsinclair相同的问题,但是使用 supportedInterfaceOrientations 方法对 UIViewController 进行子类化并没有解决问题 . 相反,我完全按照他在 AppDelegateappDidFinishLaunching 方法中所做的,并将我的 UITabBarController 作为一个孩子添加到正常的 UIViewController 而不是他的子类,并且它有效!

  • 1

    我处于相同的情况,做[self.window setFrame:...]对我不起作用 .

    在应用程序结束时添加以下内容:didFinishLaunchingWithOptions是我发现的唯一可行的方法 . 它使屏幕闪烁,并不是完全干净和高效 .

    我在应用程序结束时添加了这个:didFinishLaunchingWithOptions:

    UIViewController *portraitViewController = [[UIViewController alloc] init];
    UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:portraitViewController];
    [self.navController presentViewController:nc animated:NO completion:nil];
    [self.navController dismissViewControllerAnimated:NO completion:nil];  
    [UIViewController attemptRotationToDeviceOrientation];
    
  • 72

    我有一个类似的问题是我的应用程序在横向和纵向运行,使用UITabBarController作为根视图控制器 .

    每当应用程序在横向模式下启动时,视图不正确 .

    我所要做的就是: - 删除XIB中的rootview控制器分配 . - 启动应用程序后手动添加:


    • (void)applicationDidFinishLaunching:(UIApplication *)application {application.statusBarHidden = YES;

    [self.window setRootViewController:self.tabBarController];


    这解决了问题 .

  • 1

    只需删除支持界面方向中的所有项目,除了你想要的东西(我只需要肖像)在info.plist中,它将适用于我
    enter image description here

相关问题