Transparent Bar Backgrounds
By default, since iOS 15, UIKit bars have transparent backgrounds unless a scroll view is scrolled underneath the bar. This applies to any UINavigationBar
or UIToolbar
belonging to a UINavigationController
, or any UITabBar
belonging to a UITabBarController
.
However, to provide a more immersive viewing experience, PDFViewController
shows content underneath the navigation bar and allows the user to tap to hide this bar. Therefore, using bars with transparent backgrounds isn’t supported. PDFViewController
will automatically disable transparent bar backgrounds in these simpler setups:
-
For the navigation bar if the
PDFViewController
is a direct child of aUINavigationController
. -
For the navigation bar if the
PDFViewController
’s parent is a direct child of aUINavigationController
anduseParentNavigationBar
is enabled in thePDFConfiguration
. -
For the tab bar if the
PDFViewController
is a direct child of aUITabBarController
.
With other setups, you may see missing bar backgrounds, resulting in document content being displayed underneath bars like what’s shown below.
To fix this, you should disable transparent bar backgrounds by setting the scrollEdgeAppearance
and compactScrollEdgeAppearance
to be the same as the standardAppearance
and compactAppearance
on the navigation bar, toolbar, or tab bar.
If your PDFViewController
is a descendant of a UINavigationController
with two or more intermediate view controllers, then you can change the appearance properties of the navigation item of the direct child of the UINavigationController
. This will mean the appearance only applies when this particular view controller is the topViewController
on navigation stack:
navigationItem.scrollEdgeAppearance = navigationItem.standardAppearance navigationItem.compactScrollEdgeAppearance = navigationItem.compactAppearance
Alternatively, you can change the appearance properties of the navigation bar itself. This will apply regardless of which view controller is at the top of the navigation stack:
navigationController.navigationBar.scrollEdgeAppearance = navigationController.navigationBar.standardAppearance navigationController.navigationBar.compactScrollEdgeAppearance = navigationController.navigationBar.compactAppearance
If your PDFViewController
is a descendant of (but not a direct child of) a UITabBarController
then you can change the appearance properties of the tab bar item of the direct child of the UITabBarController
, so that this appearance only applies when this particular tab is selected:
tabBarItem.scrollEdgeAppearance = tabBarItem.standardAppearance
Alternatively, you can change the appearance properties of the tab bar itself. This will apply regardless of which tab is selected:
tabBarController.tabBar.scrollEdgeAppearance = tabBarController.tabBar.standardAppearance
If you’re using the UIToolbar
of a UINavigationController
(a bar shown at the bottom of the screen), then you must change the appearance properties of the toolbar:
navigationController.toolbar.scrollEdgeAppearance = navigationController.toolbar.standardAppearance navigationController.toolbar.compactScrollEdgeAppearance = navigationController.toolbar.compactAppearance