从第一个视图(splash)到第一个viewController的旋转问题

时间:2013-01-09 12:45:19

标签: ios6 uiinterfaceorientation uistoryboardsegue screen-rotation uiimageorientation

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

- (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或者启动时,视图都是正确的。

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

任何帮助解决这个难题的人都会非常感激!!!

1 个答案:

答案 0 :(得分:0)

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

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

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

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