作者:xXxHolicxXx900 | 来源:互联网 | 2023-01-02 17:18
我做了一个习惯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,我会得到一个白色的背景,但之后只是看起来导航栏突然出现了.我想知道是否出于某种原因被卸载然后在View Controller处于活动状态时重新加载.
--- 编辑2 ---
我有点能用黑客修复它.在我添加的AppDelegate
内部func application(... didFinishLaunchingWithOptions ...)
,self.window?.backgroundColor = UIColor.{your color}
但所有这一切都使得黑色部分现在显示为我的颜色,导航栏仍然在segue期间由于某种原因消失.