【问题标题】:Rotation issue from the first view (splash) to first viewController从第一个视图(飞溅)到第一个 viewController 的旋转问题
【发布时间】:2013-01-09 12:45:19
【问题描述】:

我在 Xcode 4.5.2 中工作,针对 iPad 应用程序的 iOS6,使用情节提要和 segues。 序言:我的根控制器(由应用程序委托加载)是一个启动屏幕,只有一个图像、一个升级按钮和一个打开按钮。应用程序需要几秒钟才能加载。我的三个全屏控制器中都有 shouldAutorotate 和 supportedInterfaceOrientations。对于轮播通知,我在根视图控制器中使用了以下两种方法:

- (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 中去图书馆工作正常,显示的边框是肖像边框。但是,在横向中,它也显示纵向边框。当从根视图处于横向时,如何使库边框以横向显示?

任何帮助解决这个难题将不胜感激!!!

【问题讨论】:

    标签: ios6 uiinterfaceorientation uistoryboardsegue screen-rotation uiimageorientation


    【解决方案1】:

    我已经找到了解决这个问题的方法... 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"];
        }
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-21
      相关资源
      最近更新 更多