1

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

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

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

灰盒

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

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

4

1 回答 1

3

经过几天的努力,我找到了一个相关的答案,表明罪魁祸首是_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
   }
}

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

于 2015-12-08T22:44:11.220 回答