这里有很多答案描述了如何以编程方式为主 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 中,可以非常清楚地看到它:
当您通过点击详细 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/