UISplitViewControllerDisplayModePrimaryOverlay 导致 "Unbalanced calls to begin/end appearance transitions"

UISplitViewControllerDisplayModePrimaryOverlay causes "Unbalanced calls to begin/end appearance transitions"

在 iOS 8 中,将 UISplitViewController 上的 preferredDisplayMode 设置为 PrimaryOverlay 会生成以下警告:

"Unbalanced calls to begin/end appearance transitions for UINavigationController"

将preferredDisplayMode设置为AllVisible或者根本不设置都没有问题。我试过的模拟器中的所有 iPad 和 iPhone 都会出现问题。应用程序以纵向或横向启动时出现问题。

下面是一些非常简单的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UITableViewController *tableViewController = [[UITableViewController alloc] init];
    UIViewController *viewController = [[UIViewController alloc] init];

    UINavigationController *masterNavController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
    UINavigationController *detailNavController = [[UINavigationController alloc] initWithRootViewController:viewController];

    UISplitViewController *svc = [[UISplitViewController alloc] init];
    [svc addChildViewController:masterNavController];
    [svc addChildViewController:detailNavController];

    //svc.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
    svc.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;

    self.window.rootViewController = svc;
    [self.window makeKeyAndVisible];

    return YES;
}

将您的显示代码包装在 dispatch_async 中。否则 iOS 似乎会同时与其他动画混淆 运行。

dispatch_async(dispatch_get_main_queue(), ^{
    svc.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
});

dispatch_async(dispatch_get_main_queue()) {
    svc.preferredDisplayMode = .PrimaryOverlay
}