Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS15 透明导航栏跳转到不透明导航栏页面的动画闪卡一下 #174

Open
selfcook opened this issue Oct 9, 2021 · 2 comments

Comments

@selfcook
Copy link

selfcook commented Oct 9, 2021

No description provided.

@xiaoMing0109
Copy link

源码中代码片段

if (@available(iOS 15, *)) {
        bar.standardAppearance = self.navigationController.navigationBar.standardAppearance;
        bar.scrollEdgeAppearance = self.navigationController.navigationBar.scrollEdgeAppearance;
    } else {
        bar.barTintColor = self.navigationController.navigationBar.barTintColor;
        [bar setBackgroundImage:[self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] forBarMetrics:UIBarMetricsDefault];
        bar.shadowImage = self.navigationController.navigationBar.shadowImage;
    }

可以看出在 iOS 15 中仅做了获取 appearance 操作,所以这部分需要自己来写了。以下为我的示例代码,希望对你有所帮助。

/// - Note: UINavigationController
override func viewDidLoad() {
        super.viewDidLoad()
        if #available(iOS 15.0, *) {
            let appearance = navigationBar.standardAppearance.copy()
            appearance.configureWithTransparentBackground()
            appearance.shadowImage = UIImage(color: .clear)
            appearance.backgroundImage = UIImage(color: .clear)
            navigationBar.standardAppearance = appearance
            navigationBar.scrollEdgeAppearance = appearance
        } else {
            navigationBar.shadowImage = UIImage(color: .clear)
        }
    }

/// - Note: UIViewController
override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let image = UIImage(color: navBarTintColor())
        /// - Note: Fix iOS 15 bug.
        if #available(iOS 15.0, *),
           let appearance = navigationController?.navigationBar.standardAppearance {
            appearance.backgroundImage = image
        } else {
            navigationController?.navigationBar.setBackgroundImage(image, for: .default)
        }

        navigationItem.title = navBarTitle()
        navigationController?.navigationBar.titleTextAttributes = navBarTitleTextAttributes()
    }

@wokua
Copy link

wokua commented Oct 20, 2021

这个我重现了,提了个pullRequest,你急的话可以先用我的fork:pod 'KMNavigationBarTransition', :git =>'https://github.com/wokua/KMNavigationBarTransition'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants