在iPhone

时间:2015-12-08 22:27:52

标签: ios ios9 uisplitviewcontroller uisplitview

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

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

在iPad上,这非常有用!但是在iPhone上有一个令人讨厌的灰色框,可以追踪主要视图。通过将该动作包装在UIView.animate块中,可以非常清楚地看到它:

Gray Box

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

如何删除这个恼人的视图?

1 个答案:

答案 0 :(得分:3)

在敲了几天之后,我发现related answer显示罪魁祸首是_UIPopoverSlidingChromeView视图。我能找到的唯一解决方案类似于上述主题的解决方案:在动画期间隐藏该视图。

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
   }
}

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