Issue with layoutMarginsGuide under iOS 26

Before I file a bug report I wanted to verify that I'm not missing something.

If I setup a view controller in a navigation controller and I add a view with a constraint that lines it up with the view controller's view's layoutMarginsGuide (leadingAnchor or trailingAnchor), in several cases the view will not line up with buttons added in the navigation bar. Under iOS 18 everything lines up as expected.

To demonstrate, create a new iOS project based on Swift/Storyboard. Setup the storyboard to show a UINavigationController with one UIViewController. Then in ViewController.swift (the one embedded in the navigation controller), use the following code:

import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .yellow

        title = "Layout Margins"

        let leftCancel = UIBarButtonItem(systemItem: .cancel)
        navigationItem.leftBarButtonItem = leftCancel
        let rightCancel = UIBarButtonItem(systemItem: .cancel)
        navigationItem.rightBarButtonItem = rightCancel

        let leftView = UIView()
        leftView.backgroundColor = .blue
        leftView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(leftView)

        let rightView = UIView()
        rightView.backgroundColor = .red
        rightView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(rightView)

        NSLayoutConstraint.activate([
            leftView.widthAnchor.constraint(equalToConstant: 80),
            leftView.heightAnchor.constraint(equalToConstant: 80),
            leftView.leadingAnchor.constraint(equalTo: self.view.layoutMarginsGuide.leadingAnchor),
            leftView.topAnchor.constraint(equalTo: self.view.layoutMarginsGuide.topAnchor),
            rightView.widthAnchor.constraint(equalToConstant: 80),
            rightView.heightAnchor.constraint(equalToConstant: 80),
            rightView.trailingAnchor.constraint(equalTo: self.view.layoutMarginsGuide.trailingAnchor),
            rightView.topAnchor.constraint(equalTo: self.view.layoutMarginsGuide.topAnchor),
        ])
    }
}

This adds a "Cancel" button to both ends of the navigation bar and it adds two little square views lined up with the leading and trailing layout margins.

Here's the results:

iPad running iPadOS 26 beta 3 (note the misalignment). This is really jarring when trying to align another glass button below the cancel button:

iPad running iPadOS 18.5 (aligned just fine):

iPhone in portrait running iOS 26 beta (aligned just fine):

iPhone in landscape running iOS 26 beta (no alignment at all):

iPhone in portrait running iOS 18.5 (aligned just fine):

iPhone in landscape running iOS 18.5 (aligned just fine):

Under iOS 26 on an iPhone (simulator at least) in portrait, the cancel buttons line up with the colored squares. That's good. In landscape, the colored squares have much larger margins as expected (due to the larger safe areas caused by the notch), but the cancel buttons in the navigation bar are not using the same margins. This one is debatable. Under iOS 18 the cancel buttons use larger margins to match the larger safe area. But I can see why under iOS 26 they changed this since the navigation bar doesn't interfere with the notch. But it's inconsistent.

Under iOS 26 on an iPad (simulator at least), it's wrong in any orientation. Despite the lack of any notch or need for a larger safe area, the colored squares are indented just a bit more than the buttons in the navigation bar. I see no reason for this. Under iOS 18 everything lines up as expected.

My real question at this point: Is the mismatched margins on an iPad under iOS 26 between the buttons in the navigation bar and other views added to the view controller a likely bug or am I missing something?

Seems like a good bug report to me! I don’t see anything missing, or have an explanation for the different behavior, so seems it could be not working as expected.

I submitted bug FB18883173

Issue with layoutMarginsGuide under iOS 26
 
 
Q