iphone - 支持多界面,但主屏幕只有单一界面,在 iOS8 + iPhone 中不工作

标签 iphone uiviewcontroller orientation ios8 xcode6

我的 View 结构如下。

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

问题:
当我coming back from View2(Landscape mode)HomeView通过调用 popToRootViewController方法,它没有调用 supportedInterfaceOrientationsForWindow App_Delegate方法并显示 首页查看 landscape mode

图片:

enter image description here

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

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

在上面的链接中mattiOS8 stop support for friezing orientation ,但我在apple document中没有找到它 如果您有的话reference link请分享有关此更改的信息。

问题:
1] 为什么委托(delegate)方法supportedInterfaceOrientationsForWindow没有调用。
2] 是否有可能有一个 View 支持单一方向,而所有其他 View 将支持所有方向。

谢谢

最佳答案

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

问题:
我在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 未调用 当堆栈中存在超过两个 View Cotnrollers时使用popToRootViewControllerAnimated方法。

解决方案:
Step1:创建导航 Controller 的子类。

Step2:重写popToRootViewControllerAnimated方法并编写如下代码 //覆盖父类(super class)方法 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];
    }
}


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

关于iphone - 支持多界面,但主屏幕只有单一界面,在 iOS8 + iPhone 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25769068/

相关文章:

ios - 能不能有个UIView "ignore"界面定位?

iphone - 手机网站 : Orientation change from portrait to horizontal

ios - 为什么我的 iPhone 应用程序在 iPad 上全屏运行

iphone - 如何在 UIView 中获取父级导航 Controller

iphone - 在 Unknown Person ViewController 中添加导航栏

vb.net - 在 vb.net 中更正图像方向服务器端

ios - UIImageOrientation 到 CIDetectorImageOrientation

iphone - 使用 Xcode 处理循环中对象的正确方法

ios - xcode/swift 中类名的错误?

ios - 当我回到 Viewcontroller 时如何更改 View Controller 的 label.text?