支持多接口,但在主屏幕中具有单一界面,无法在iOS 8 + iPhone中运行

时间:2014-09-10 15:14:12

标签: iphone uiviewcontroller orientation ios8 xcode6

我有如下的视图结构。

HomeView(Support only portrait mode)
 |
 |
 V
View1(Support all orientation)
 |
 |
 V
View2(Support all orientation)

问题:
当我通过调用coming back from View2(Landscape mode)方法HomeViewpopToRootViewController时,它没有调用 supportedInterfaceOrientationsForWindow App_Delegate 的方法,显示 landscape mode 中的HomeView。

图片:

enter image description here

注意:
当我通过调用popToRootViewController方法从View1(横向模式)返回到HomeView时,同样的事情不会发生 它将调用supportedInterfaceOrientationsForWindow并且所有工作都很棒 如果我在iOS7中使用XCode6运行app,一切都很好。

I read below question but it did not help me
How to maintain presenting view controller's orientation when dismissing modal view controller?

在上面的链接matt中说 iOS8 stop support for friezing orientation ,但我没有在apple document中找到它 如果您对此更改有任何reference link,请分享。

问题:
1]为什么委托方法supportedInterfaceOrientationsForWindow没有调用。
2]是否可以使一个视图具有支持单一方向,而所有其他视图将支持所有方向。

感谢

1 个答案:

答案 0 :(得分:3)

我解决了问题并发布了答案,因为它可能有助于某些人

问题:
我在supportedInterfaceOrientationsForWindow中有以下代码。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    // Suport only portrait mode for home screen
    if([self.navigationController.topViewController isKindOfClass:[ViewHome class]])

    {
        return UIInterfaceOrientationMaskPortrait;
    }
    return UIInterfaceOrientationMaskAll;
}

但未调用delegate方法supportedInterfaceOrientationsForWindow 当堆栈中存在popToRootViewControllerAnimated时使用more then two view Cotnrollers方法时。

解决方案:
第1步:创建导航控制器的子类。

Step2:覆盖方法popToRootViewControllerAnimated并编写如下代码 //覆盖超类方法popToRootViewControllerAnimated。

-(NSArray*)popToRootViewControllerAnimated:(BOOL)animated
{
    // Only for iOS8 and above
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
    {
        // Array which will contaimn all poped view controllers object.
        NSMutableArray *popedControllersArray = [[NSMutableArray alloc] init];

        // Tmp created controllers object
        NSArray *controllers;

        // Hold first view cotnrollers.
        UIViewController *firstViewController = [self.viewControllers objectAtIndex:1];

        // Pop to first view controllers with no animation.
        controllers = [super popToViewController:firstViewController animated:NO];

        // Add poped view cotnrollers objects to the array.
        [popedControllersArray addObjectsFromArray:controllers];

        // Pop to root view controller with animation
        [super popViewControllerAnimated:YES];

        // Add first view controller object as it is poped by above line.
        [popedControllersArray addObject:firstViewController];

        // return poped view controllers object.
        return popedControllersArray;
    }
    else
    {
        // Called super view popToRootViewControllerAnimated method and return popped
        // view controllers array.
        return [super popToRootViewControllerAnimated:animated];
    }
}


请免费填写任何评论并提出任何问题。