支持多接口但在主屏幕中具有单一界面,在iOS8 + iPhone中不起作用

Jag*_*een 7 iphone orientation uiviewcontroller xcode6 ios8

我有如下的视图结构.

HomeView(Support only portrait mode)
 |
 |
 V
View1(Support all orientation)
 |
 |
 V
View2(Support all orientation)
Run Code Online (Sandbox Code Playgroud)

问题:
当我coming back from View2(Landscape mode)HomeView调用popToRootViewController的方法,它没有调用supportedInterfaceOrientationsForWindow的方法App_Delegate并显示 在HomeViewlandscape mode.

图片:

在此输入图像描述

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

I read below question but it did not help me.
解雇模态视图控制器时如何保持显示视图控制器的方向?

在上面的链接mattiOS8 stop support for friezing orientation,但我没有找到它,apple document 如果你有任何reference link关于这个改变请分享.

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

谢谢

Jag*_*een 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;
}
Run Code Online (Sandbox Code Playgroud)

但是当堆栈中存在该方法时,使用该方法时不会调用delegate该方法。解决方案: 步骤1:创建导航控制器的子类。supportedInterfaceOrientationsForWindowpopToRootViewControllerAnimatedmore then two view Cotnrollers


步骤2:重写方法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];
    }
}
Run Code Online (Sandbox Code Playgroud)


请免费填写任何意见并提出任何问题。


归档时间:

查看次数:

3388 次

最近记录:

11 年,7 月 前