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

iOS 15 Nav Appearance Updates Remove Transparent Navigation Bar in photo viewer #348

Open
justColbs opened this issue Feb 2, 2022 · 2 comments

Comments

@justColbs
Copy link

The navigation bar in the overlayView is using the global values I set in my AppDelegate, but only in iOS 15. My AppDelegate:

if #available(iOS 13.0, *) {
            let ap = UINavigationBarAppearance()
            ap.backgroundColor = UIColor.HBlue()
            ap.titleTextAttributes = convertToOptionalNSAttributedStringKeyDictionary([NSAttributedString.Key.foregroundColor.rawValue: UIColor.white, NSAttributedString.Key.font.rawValue: Constants.Fonts.NavigationItemTitleFont!])!
            UINavigationBar.appearance().scrollEdgeAppearance = ap
            UINavigationBar.appearance().standardAppearance = ap
}
        UINavigationBar.appearance().isTranslucent = false

I've seen this issue, but it's recommended solution didn't work for me. iOS 15 introduces some different changes to UINavigationBar's appearance and I believe that's causing this issue.

Any workaround for this so that the navigation bar on the photo viewer remains transparent?

The issue:
Simulator Screen Shot - iPhone 12 - 2022-02-02 at 15 21 52

@justColbs justColbs changed the title iOS 15 Navigation Bar Appearance Removes Transparent Navigation Bar iOS 15 Nav Appearance Updates Remove Transparent Navigation Bar in photo viewer Feb 2, 2022
@jeremyteh
Copy link

jeremyteh commented Mar 21, 2022

In my case, I have encountered similar issue when using the following library to display photos in iOS15 devices.

As such, I have added the following snippet of code into the viewDidLoad method in NYTPhotosViewController:

- (void)viewDidLoad {
    [super viewDidLoad];
    if (@available(iOS 15.0, *)) {
             
         UINavigationBarAppearance *navBarAppearance = [[UINavigationBarAppearance alloc] init];
         [navBarAppearance configureWithOpaqueBackground];
         navBarAppearance.backgroundColor = [UIColor colorWithRed: 0.0/255.0 green: 0.0/255.0 blue: 0.0/255.0 alpha:1.0];
         [[UINavigationBar appearance] setStandardAppearance:navBarAppearance];
         [[UINavigationBar appearance] setScrollEdgeAppearance:navBarAppearance];
    }
    ...
}

After adding the following snippet, I was able to achieve the correct navbar appearance.
Navbar color issue for NYT Photo Viewer

Since my app theme is yellow in color, and I have set it in the AppDelegate, I will proceed to set back to the navbar color before the view controller dissapears in the viewDidDisappear method in NYTPhotosViewController:

- (void)viewDidDisappear:(BOOL)animated {
     [super viewDidDisappear:animated];
     if (@available(iOS 15.0, *)) {
        
        UINavigationBarAppearance *navBarAppearance = [[UINavigationBarAppearance alloc] init];
        [navBarAppearance configureWithOpaqueBackground];
        navBarAppearance.backgroundColor = [UIColor colorWithRed: 252.0/255.0 green: 222.0/255.0 blue: 54.0/255.0 alpha: 1.0];
        [[UINavigationBar appearance] setStandardAppearance:navBarAppearance];
        [[UINavigationBar appearance] setScrollEdgeAppearance:navBarAppearance];
    }
    ...
}

Hope the following is helpful in resolving your issue!

@JeromeBeckett
Copy link

As an addendum to @jeremyteh's comment above, I found I had to add the final code snippet into viewWillDisappear instead of viewDidDisappear so that the navigation bar is reset before it is dismissed, not after, otherwise the colour reset is triggered too late and will not display until it is repainted a further time.

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