ios - 从 iPhone 中的 PrimaryOverlay 动画到 PrimaryHidden 时隐藏 UiSplitView 中的灰色框

标签 ios ios9 uisplitviewcontroller uisplitview

这里有很多答案描述了如何以编程方式为主 Split View设置动画:

let addButton = self.splitViewController!.displayModeButtonItem()
UIApplication.sharedApplication().sendAction(addButton.action, to: addButton.target, from: nil, forEvent: nil)

在 iPad 上,这非常有效!但在 iPhone 上,主视图后面有一个恼人的灰色框。通过将该 Action 包装在 UIView.animate block 中,可以非常清楚地看到它:

Gray Box

当您通过点击详细 View 实际关闭主视图时,该框几乎不可见,但当您以编程方式关闭它时真的很烦人。

我怎样才能消除这个恼人的观点?

最佳答案

经过几天的努力,我发现了一个related answer显示罪魁祸首是_UIPopoverSlidingChromeView看法。我能找到的唯一解决方案类似于上述主题的解决方案:在动画期间隐藏该 View 。

var foundChrome = false
var view: UIView! = self.view
var popView: UIView!

let displayModeButton = self.splitViewController!.displayModeButtonItem()

while view != nil {
   //print("View: ", Mirror(reflecting: view).subjectType, " frame: \(view.frame)")

   if let sv = view {
      if Mirror(reflecting: sv).description.containsString("Popover") { // _UIPopoverView
         for v in sv.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
}
if foundChrome {
   let duration: NSTimeInterval = 2.0
   UIView.animateWithDuration(duration, animations: { () -> Void in
      UIApplication.sharedApplication().sendAction(displayModeButton.action, to: displayModeButton.target, from: nil, forEvent: nil)
   })
   // must do this separately, doing in a completion block doesn't work, as it takes affect too soon
   let t = dispatch_time(DISPATCH_TIME_NOW, Int64(duration * NSTimeInterval(NSEC_PER_SEC)))
   dispatch_after(t, dispatch_get_main_queue()) {
      popView.hidden = false
   }
}

我意识到这有点深奥,但如果你遇到这个问题,你会很高兴以任何方式解决它。

关于ios - 从 iPhone 中的 PrimaryOverlay 动画到 PrimaryHidden 时隐藏 UiSplitView 中的灰色框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34167266/

相关文章:

ios:UITableView 不会滚动到底部

ios - 无法在 iOS 9 上验证应用程序

swift - iOS 14 UISplitViewController(侧边栏)与三栏侧边栏切换图标行为

ios - 是否可以使用现有的 View Controller 为 iPad 实现 Split View

iphone - SplitViewController 中的 UIPopoverController

ios - 比较值并在 uitableview 中显示特定结果

iphone - IframeExtractor 不使用 rtsp 输出声音

ios - 使用自动布局在 UIView 内水平居中 UILabel + UIImageView

ios - 使用 Storyboard进行 iOS 开发

localization - iOS9 强制 LTR UINavigationController 推送方向用于 RTL 语言