Skip to content

26系统下,隐藏导航栏的横屏页面退回到有导航栏的竖屏页面时,UI布局闪动 #1706

@a714857512

Description

@a714857512

Bug 表现
在iOS 26系统下,从一个隐藏导航栏的横屏页面返回到一个有导航栏的竖屏页面,横竖屏约束的切换动画会闪动(动画执行到一半的时候,直接变成了竖屏的约束,26之前的系统不存在这个情况)。

截图

如何重现
如问题描述

预期的表现
不闪动,下面是AI的解决方法

// MARK: - iOS 26 导航转场布局兼容
private extension EHBaseViewControllerSwift {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
applyIOS26NavigationTransitionLayoutWorkaroundIfNeeded(animated: animated)
}

func applyIOS26NavigationTransitionLayoutWorkaroundIfNeeded(animated: Bool) {
    guard animated,
          #available(iOS 26.0, *),
          let coordinator = transitionCoordinator ?? navigationController?.transitionCoordinator,
          let fromViewController = coordinator.viewController(forKey: UITransitionContextViewControllerKey.from),
          let toViewController = coordinator.viewController(forKey: UITransitionContextViewControllerKey.to),
          toViewController === self,
          fromViewController.supportedInterfaceOrientations != toViewController.supportedInterfaceOrientations else {
        return
    }

    guard let targetView = view else { return }

    let updateLayoutWithoutAnimation = {
        UIView.performWithoutAnimation {
            // iOS 26 + QMUI 导航栏显隐转场叠加方向变化时,目标页布局可能被系统插入到转场动画中。
            // 在目标页 viewWillAppear 阶段跟随 coordinator 做无动画布局,避免横竖屏转场中途闪跳。
            targetView.setNeedsLayout()
            targetView.superview?.setNeedsLayout()
            targetView.superview?.layoutIfNeeded()
            targetView.layoutIfNeeded()
        }
    }

    let didRegister = coordinator.animate(alongsideTransition: { _ in
        updateLayoutWithoutAnimation()
    }, completion: nil)
    if didRegister == false {
        updateLayoutWithoutAnimation()
    }
}

}

其他信息

  • 设备: [例如模拟器、iPhone、iPad]
  • iOS 版本: [iOS 26.x]
  • Xcode 版本: [Xcode 26.x]
  • QMUI 版本: [https://github.com/CloudlessMoon/QMUI_iOS.git]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions