从第一个视图(splash)到第一个viewController的旋转问题 [英] Rotation issue from the first view (splash) to first viewController

查看:156
本文介绍了从第一个视图(splash)到第一个viewController的旋转问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode 4.5.2中工作,使用故事板和segues将iOS6用于iPad应用。
前言:我的根控制器(由app delegate加载)是一个启动画面,只有一个图像,一个升级按钮和一个打开按钮。应用程序需要几秒钟才能加载。我在所有三个全屏幕控制器中都有应该启用和支持接口方向。对于循环通知,我在根视图控制器中使用以下两种方法:

I am working in Xcode 4.5.2, targeting iOS6 for an iPad app, using storyboards and segues. Preamble: my root controller (loaded by the app delegate) is a splash screen with only an image, an upgrade button and an open button. App takes a few seconds to load. I have shouldAutorotate and supportedInterfaceOrientations in all three of my full screen controllers. For rotation notification, I am using the following two methods in my root view controller:

- (void)awakeFromNib
{
    [UIDevice.currentDevice beginGeneratingDeviceOrientationNotifications];
    [NSNotificationCenter.defaultCenter addObserver:self
                                       selector:@selector(orientationChanged:)
                                           name:UIDeviceOrientationDidChangeNotification
                                         object:nil];
}

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation))
    {
        // Landscape
        CGRect rect = _libraryViewController.libraryTableBorder.frame;
        _libraryViewController.libraryTableBorder.frame = rect;
        _libraryViewController.libraryTableBorder.image = [UIImage imageNamed:@"LibraryBorder_L.png"];
    }
    else if (UIDeviceOrientationIsPortrait(deviceOrientation))
    {
        // Portrait
        CGRect rect = _libraryViewController.libraryTableBorder.frame;
        _libraryViewController.libraryTableBorder.frame = rect;
        _libraryViewController.libraryTableBorder.image = [UIImage imageNamed:@"LibraryBorder_P.png"];
    }
}

我在LibraryViewController中有这些相同的方法工作得很好。我有另一个主视图控制器(entryView)具有相同的方法,没有对libraryTableBorder的调用。无论设备来自或进入入口视图的旋转方式,表边框都会正确切换。并且,当从库到entryView或者启动时,视图都是正确的。

I have these very same methods in the LibraryViewController and it works perfectly. I have another main view controller (entryView) that has the same methods without the calls for the libraryTableBorder. No matter what rotation the device is in coming from or going to the entry view, the table border swaps out correctly. And, when going from the library to either the entryView or to the splash, the views are correct.

问题是从横向的启动视图到库。去Potrait的图书馆工作正常,显示的边框是纵向边框。但是,在横向中,它还会显示纵向边框。如果在横向视图中从根视图进入时,如何让图书馆边框以横向显示?

The issue is going from the splash view in landscape to the library. Going to the library in Potrait works fine and the border displayed is the portrait border. But, in landscape, it also displays the portrait border. How can I get the library border to display in landscape when coming from the root view when it is in landscape?

任何帮助解决这个难题都将非常感谢!! !

Any help in solving this conundrum would be much appreciated!!!

推荐答案

我找到了解决这个问题的方法... viewWillLayoutSubviews

I have found the solution to this issue... viewWillLayoutSubviews

我被另一个线程提示,它指向了iOS6的发行说明。我添加了UIDeviceOrientation和我的if / else语句。现在边框正确旋转,无论我去哪个视图或来自哪个视图!

I was prompted by another thread, which pointed to the release notes for iOS6. I added the UIDeviceOrientation and my if/else statement to it. Now the border rotates correctly, regardless of which view I go to or come from!

- (void)viewWillLayoutSubviews
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation))
    {
        // Landscape
        CGRect rect = _libraryTableBorder.frame;
        _libraryTableBorder.frame = rect;
        _libraryTableBorder.image = [UIImage imageNamed:@"LibraryBorder_L.png"];
    }
    else if (UIDeviceOrientationIsPortrait(deviceOrientation))
    {
        // Portrait
        CGRect rect = _libraryTableBorder.frame;
        _libraryTableBorder.frame = rect;
        _libraryTableBorder.image = [UIImage imageNamed:@"LibraryBorder_P.png"];
    }
}

这对我来说肯定是令人沮丧的问题。希望这有助于其他人!

This was sure a frustrating issues for me. Hope this helps someone else!

这篇关于从第一个视图(splash)到第一个viewController的旋转问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆