That doesn’t solve my issue:
The video only handles cases where a navigation bar is already at the top of the main screen. Please advise what can be done if this is not the case (as for my main screen).
On my settings screen (a table view with a navigation bar on top), I implemented your sample code, but the left-bar button on the navigation controller’s bar still doesn’t move and remains covered by the window controls. I must be doing something wrong.
Based on another user’s suggestion and also your video, I tried using UISceneWindowingControlStyleMinimal in my SceneDelegate.
Still about a third of the left-bar button is obscured by the window controls.
Here’s my Objective-C code (based on your Swift code) in the navigation bar subclass:
UIView *containerView = self.view;
UIView *contentView = self.navigationBar;
UILayoutGuide *contentGuide;
UIViewLayoutRegion *marginsRegion =
[UIViewLayoutRegion marginsLayoutRegionWithCornerAdaptation:
UIViewLayoutRegionAdaptivityAxisHorizontal];
contentGuide = [containerView layoutGuideForLayoutRegion:marginsRegion];
// Pin all four edges of the content view to that guide
[NSLayoutConstraint activateConstraints:@[
[contentView.topAnchor constraintEqualToAnchor:contentGuide.topAnchor],
[contentView.leadingAnchor constraintEqualToAnchor:contentGuide.leadingAnchor],
[contentView.bottomAnchor constraintEqualToAnchor:contentGuide.bottomAnchor],
[contentView.trailingAnchor constraintEqualToAnchor:contentGuide.trailingAnchor],
]];