过渡到透明 UINavigationBar(Apple Music 类似导航栏)

Transition to Transparent UINavigationBar (Apple Music like Navigation Bar)

我正在尝试复制 iOS 音乐应用 push/pop 从半透明到透明 UINavigationBar 的过渡,同时保持 UIBarButtonItems 可见。由于导航栏不会自行移动,我认为您需要为两个 UIViewControllers 设置 UINavigationBar 透明,并在透明 UINavigationBar 下的 UIViewController 添加子视图以模拟半透明 UINavigationBar。这个问题有什么解决方案吗?

这些是我找到的最好的 github 存储库:

https://github.com/forkingdog/FDFullscreenPopGesture https://github.com/kingiol/KDInteractiveNavigationController https://github.com/MoZhouqi/KMNavigationBarTransition

在您的详细信息控制器上输入此代码

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    guard self.navigationController?.topViewController === self else {return}

    self.transitionCoordinator()?.animateAlongsideTransition({ [weak self](context) in
        self?.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
        self?.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)

        }, completion: { context in
    })
}

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(animated)

    guard self.navigationController?.topViewController === self else {return}

    self.transitionCoordinator()?.animateAlongsideTransition({ [weak self](context) in
        self?.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default)
        self?.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: .Default)
        }, completion: { context in
    })
}