HomeiOS Developmentuikit - iOS 26 navigation bar's place is positioned decrease than iOS...

uikit – iOS 26 navigation bar’s place is positioned decrease than iOS 18 in panorama mode


My app merely accommodates a navigation bar, and see that iOS 26 renders it decrease than anticipated. As you’ll be able to see from the screenshot, it is positioned at 24 pt down. Nonetheless, on iOS 18, the navigation bar is positioned on the prime.

The iOS 26 model takes an excessive amount of display house and would not look good. How can I modify it to match iOS 18 conduct?

This is a minimal repro code:


import UIKit

class ViewController: UIViewController {

  override func viewDidLoad() {
    tremendous.viewDidLoad()
    // Do any further setup after loading the view.
    
    let w: CGFloat = 64
    let h: CGFloat = 64

    let v1 = UIView(body: CGRectMake(0, 0, w, h))
    let v2 = UIView(body: CGRectMake(0, 0, w, h))
    let v3 = UIView(body: CGRectMake(0, 0, w, h))
    let v4 = UIView(body: CGRectMake(0, 0, w, h))
    let v5 = UIView(body: CGRectMake(0, 0, w, h))
    let v6 = UIView(body: CGRectMake(0, 0, w, h))

    v1.backgroundColor = .purple
    v2.backgroundColor = .inexperienced
    v3.backgroundColor = .yellow
    v4.backgroundColor = .grey
    v5.backgroundColor = .cyan
    v6.backgroundColor = .purple
    
    let views: [UIView] = [v1, v2, v3, v4, v5, v6]
    
    let hole: CGFloat = 16
    let width: CGFloat = 32
    let top: CGFloat = 32
    let totalWidth: CGFloat = width * CGFloat(views.depend) + hole * CGFloat(views.count-1)
    let container = UIView(body: CGRectMake(0, 0, totalWidth, top))
    
    container.widthAnchor.constraint(equalToConstant: totalWidth).isActive = true
    
    for (i, view) in views.enumerated() {
        view.translatesAutoresizingMaskIntoConstraints = false
        container.addSubview(view)

        NSLayoutConstraint.activate([
            view.widthAnchor.constraint(equalToConstant: width),
            view.heightAnchor.constraint(equalToConstant: height), // match container
            view.centerYAnchor.constraint(equalTo: container.centerYAnchor),
            view.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: CGFloat(i) * (width + gap))
        ])
    }
    
    let containerItem = UIBarButtonItem(customView: container)
    if #obtainable(iOS 26.0, *) {
      containerItem.hidesSharedBackground = true
    }

    navigationItem.rightBarButtonItem = containerItem
  }
}

extension UIView {
  func anchor(to dimension: CGSize) {
    translatesAutoresizingMaskIntoConstraints = false
    let constraints = [
      heightAnchor.constraint(equalToConstant: size.height),
      widthAnchor.constraint(equalToConstant: size.width)
    ]
    for constraint in constraints {
      constraint.precedence = UILayoutPriority(rawValue: 1000)
    }
    NSLayoutConstraint.activate(constraints)
  }
}

On iOS 26 (see the hole):

enter image description here

On iOS 18 (no hole):
enter image description here

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments