支持多界面但在主屏幕有单一界面在 iOS8 + iPhone 中不起作用 [英] Supporting Multiple Interface but have single interface in home screen not working in iOS8 + iPhone

查看:15
本文介绍了支持多界面但在主屏幕有单一界面在 iOS8 + iPhone 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下视图结构.

I have view structure like below.

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

问题:
当我通过调用 popToRootViewController 方法从 View2(横向模式) 返回到 HomeView 时,它没有调用 supportedInterfaceOrientationsForWindow App_Delegate 的方法和显示横向模式的HomeView.

Problem :
When i am coming back from View2(Landscape mode) to HomeView by calling popToRootViewController method,It did not call supportedInterfaceOrientationsForWindow method of App_Delegate and display HomeView in landscape mode.

图片:

注意:
当我通过调用 popToRootViewController 方法从 View1(横向模式)返回到 HomeView 时,同样的事情不会发生它将调用 supportedInterfaceOrientationsForWindow 并且一切正常.
如果我在 iOS7 中使用 XCode6 运行应用程序,则一切正常.

Note :
Same thing not happens when i came back from View1(Landscape mode) to HomeView by calling popToRootViewController method it will call supportedInterfaceOrientationsForWindow and all works great.
If I run app using XCode6 in iOS7 all works great.

我阅读了以下问题,但对我没有帮助.
关闭模态时如何保持呈现视图控制器的方向视图控制器?

在上面的链接matt中说iOS8停止支持friezing方向,但我在apple文档中没有找到它如果您有任何关于此更改的参考链接,请分享.

In above link matt said that iOS8 stop support for friezing orientation, but I did not find it in apple document if you have any reference link about this change please share.

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

谢谢

Question :
1] Why delegate method supportedInterfaceOrientationsForWindow is not calling.
2] Is it possible to have one view with support single orientation and all other will support all orientation.

Thanks

推荐答案

我解决了它并发布了答案,因为它可能会对某些人有所帮助

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

Problem :
I have below code in 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 方法时,超过两个视图 Cotnrollers 存在于堆栈中.

解决方案:
Step1:创建导航控制器的子类.

But delegate method supportedInterfaceOrientationsForWindow not called when use popToRootViewControllerAnimated method when there ismore then two view Cotnrollersexists in stack.

Solution :
Step1: Create sub class of Navigation controller.

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

Step2: Override method popToRootViewControllerAnimated and write code as below // Overwrite super class method 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];
    }
}


如有任何意见和问题,请免费填写.

Please fill free for any comments and ask for any questions.

这篇关于支持多界面但在主屏幕有单一界面在 iOS8 + iPhone 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆