QMUI_iOS icon indicating copy to clipboard operation
QMUI_iOS copied to clipboard

QMUIButton使用约束布局在vc.navigationItem.titleView上时可能会导致闪退

Open CloudlessMoon opened this issue 3 months ago • 3 comments

Bug 表现 QMUIButton使用约束布局在vc.navigationItem.titleView上时可能会导致闪退

截图

Image

The layout constraints still need update after sending -updateConstraints to <_UINavigationBarTitleControl: 0x15b298300; frame = (0 0; 0 0); layer = <CALayer: 0x15ae2ca20>>. _UINavigationBarTitleControl or one of its superclasses may have overridden -updateConstraints without calling super. Or, something may have dirtied layout constraints in the middle of updating them. Both are programming errors.

如何重现 ① 设置QMUIButton.translatesAutoresizingMaskIntoConstraints = fasle,完整代码如下图所示:

Image

② 设置vc.navigationItem.titleView 为如上图所示的 QDTestTitleView

Image

③ present这个vc

Image

注意:以上步骤缺一不可

这个评论https://github.com/Tencent/QMUI_iOS/issues/1679#issuecomment-3413966005 有可能是同一个问题导致

预期的表现 正常情况下,应该不会崩溃

其他信息

  • 设备: iPhone 11或者iPhone 11模拟器
  • iOS 版本: iOS 26.0
  • Xcode 版本: Xcode 26.0
  • QMUI 版本: 4.8.0

CloudlessMoon avatar Oct 23 '25 01:10 CloudlessMoon

经测试得出是_UINavigationBarTitleControl的Bug,如下图所示: Image

intrinsicContentSize里调用layoutIfNeeded就会触发上述问题,不仅仅是QMUIButton的问题。

CloudlessMoon avatar Oct 24 '25 09:10 CloudlessMoon

我也试了[self.navigationItem setTitleView:self.navView]; 当navView里只有一个按钮时并不会触发此崩溃,但有两个按钮时,就会触发 请问这种情况当前简单优化方案是怎么样的?

fengshh93 avatar Nov 17 '25 03:11 fengshh93

我也试了[self.navigationItem setTitleView:self.navView]; 当navView里只有一个按钮时并不会触发此崩溃,但有两个按钮时,就会触发 请问这种情况当前简单优化方案是怎么样的?

https://github.com/Tencent/QMUI_iOS/pull/1672/commits/3ef2a3d4f54feb89260bf6e7d540b81ef97c658c iOS 26.0的bug,实测26.1及以上就没问题了,安全起见先这么放着,等迭代几个iOS版本后再加上版本兼容

CloudlessMoon avatar Nov 17 '25 05:11 CloudlessMoon