我如何在iOS中实现Smooth UINavigationBar颜色更改转换

时间:2018-04-24 03:33:57

标签: ios swift xcode uikit

我正在尝试使UINavigationBar颜色过渡平滑。 我环顾四周,正在使用(this)方法。

ChildViewController我有下面提到的代码:

//Transition to transparent navbar
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            UIView.animate(withDuration: 0.1) {
                self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
                self.navigationController?.navigationBar.shadowImage = UIImage()
                self.navigationController?.navigationBar.barStyle = .black
                self.navigationController?.navigationBar.layoutIfNeeded()
            }
        }

// Transition to default Navbar
        override func willMove(toParentViewController parent: UIViewController?) {
                self.navigationController?.navigationBar.barStyle = .default
                self.navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
                self.navigationController?.navigationBar.shadowImage = nil
                self.navigationController?.navigationBar.barTintColor = nil
        }

ChildViewControllerparent

缓慢滑动时,结果会产生闪烁效果

enter image description here

0 个答案:

没有答案