Rotation issue from the first view (splash) to first viewController

痞子三分冷 提交于 2019-12-12 04:48:26

问题


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"];
    }
}

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.

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!!!


回答1:


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

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!



来源:https://stackoverflow.com/questions/14235494/rotation-issue-from-the-first-view-splash-to-first-viewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!