【发布时间】:2018-06-14 21:20:40
【问题描述】:
我自定义了UIStoryboardSegue,但是当它展开时,它似乎导致我的UINavigationBar 变黑,然后又恢复到正确的颜色。请参阅下面的 GIF。
我的自定义 segue 只是让新的 ViewController 从顶部下来,然后回到顶部。
这里是UIStoryboardSegue 代码:
import UIKit
class SlideDownSegue: UIStoryboardSegue {
var duration: Double = 0.5
override func perform() {
let screenHeight = UIScreen.main.bounds.size.height
let toVC = self.destination
let fromVC = self.source
toVC.view.transform = CGAffineTransform(translationX: 0, y: -screenHeight)
UIApplication.shared.keyWindow?.insertSubview(toVC.view, aboveSubview: fromVC.view)
UIView.animate(withDuration: duration, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
toVC.view.transform = CGAffineTransform.identity
}, completion: {
success in
fromVC.present(toVC, animated: false, completion: nil)
})
}
}
class UnwindSlideDownSegue: UIStoryboardSegue {
override func perform() {
let screenHeight = UIScreen.main.bounds.size.height
let toVC = self.destination
let fromVC = self.source.parent!
fromVC.view.superview?.insertSubview(toVC.view, at: 0)
UIView.animate(withDuration: 0.5, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
fromVC.view.transform = CGAffineTransform(translationX: 0, y: -screenHeight - 100)
}, completion: {
success in
fromVC.dismiss(animated: false, completion: nil)
})
}
}
如果我通过转到屏幕底部让展开执行它刚刚离开的默认位置,但保留我的自定义以显示新视图,UINavigationBar 保持它的正确颜色,只有当我使用我的代码时用于在动画期间使 UINavigationBar 变黑的放松。
任何提示将不胜感激。
---编辑---
我玩了一下,如果我进入 AppDelegate 并将UINavigationBar.appearance().isTranslucent = false 更改为true,我会得到一个白色背景,但它只是看起来导航栏突然出现了。我想知道是否由于某种原因被卸载,然后在视图控制器处于活动状态后重新加载。
---编辑 2---
我可以通过 hack 来修复它。在AppDelegate 里面func application(... didFinishLaunchingWithOptions ...) 我添加了self.window?.backgroundColor = UIColor.{your color} 但所做的只是让黑色部分现在出现我的颜色,导航栏由于某种原因在segue期间仍然消失。
【问题讨论】:
-
尝试设置导航控制器视图的背景颜色以匹配。既然你这样做了,你可以添加另一个 gif 吗?
标签: uinavigationbar ios11 swift4 uistoryboardsegue xcode9