奇怪的底层灰色概述视图试图通过编程解雇UISplitViewController的主人

我使用UISplitViewControllerpreferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay ,我正在寻找一种方法来解除主视图控制器。 我的主人包含一个表格视图,我想closures它,只要我select一个单元格。 令人惊讶的UISplitViewController似乎并没有提供一个方法(但我确实看到苹果电脑公司正在做,我们你select在纵向模式下的电子邮件)。

我发现这里报告了以下解决方法: 在iOS8中隐藏与主视图控制器与UISplitViewController (请看phatmann答案)。 这种方法很有效,但是当它被解散时,它也会产生一个奇怪的animation,这里有一个底层的灰色轮廓视图,与主人的观点不一致。 这个问题在这里也有报道: iOS Swift 2 UISplitViewController在iPad / iPhone 6+上打开主屏幕上的详细屏幕

只有当我解雇主这个解决方法,而不是当我点击辅助,所以我猜UISplitViewController是不是跟随常规解雇stream,当你只是在button上调用sendAction时,会出现问题。

我用下面的代码来解决这个问题。 可能有更好的方法来匹配导致问题的具体观点。 也就是说,这个代码是在今年四月苹果批准的应用程序。 代码所做的是查找特定types的特定视图,如果find,则会隐藏它,直到animation完成。 它有点前途的证据,因为如果它没有检测到特殊的观点,它什么都不做。 我还为采纳者添加了一些意见,以便您可以在其中进行更改。

 func closePrimaryIfOpen(finalClosure fc: (() -> Void)? = nil) { guard let primaryNavController = viewControllers[0] as? MySpecialNavSubclass, primaryVC = primaryNavController.topViewController as? MySpecialCalss else { fatalError("NO Special Class?") } // no "official" way to know if its open or not. // The view could keep track of didAppear and willDisappear, but those are not reliable let isOpen = primaryVC.view.frame.origin.x >= -10 // -10 because could be some slight offset when presented if isOpen { func findChromeViewInView(theView: UIView) -> UIView? { var foundChrome = false var view: UIView! = theView var popView: UIView! repeat { // Mirror may bring in a lot of overhead, could use NSStringFromClass // Also, don't match on the full class name! For sure Apple won't like that! //print("View: ", Mirror(reflecting: view).subjectType, " frame: \(view.frame)") if Mirror(reflecting: view).description.containsString("Popover") { // _UIPopoverView for v in view.subviews { //print("SV: ", Mirror(reflecting: v).subjectType, " frame: \(v.frame)") if Mirror(reflecting: v).description.containsString("Chrome") { foundChrome = true popView = v //popView.hidden = true break } } if foundChrome { break } } view = view.superview } while view != nil return popView } // Note: leave it as optional - Apple changes things and we don't find the view, things still work! let chromeView = findChromeViewInView(self.view) UIView.animateWithDuration(0.250, animations: { chromeView?.hidden = true self.preferredDisplayMode = .PrimaryHidden }, completion: { Bool in self.preferredDisplayMode = .PrimaryOverlay chromeView?.hidden = false if let finalClosure = fc { finalClosure() } //print("SLIDER CLOSED DONE!!!") } ) } }