swift – Xcode 9 / iOS 11“CALayer界限包含NaN:[nan 0; nan 0]“当使用嵌套的UINavigationController和UITabBarController弹出视图控制器时

前端之家收集整理的这篇文章主要介绍了swift – Xcode 9 / iOS 11“CALayer界限包含NaN:[nan 0; nan 0]“当使用嵌套的UINavigationController和UITabBarController弹出视图控制器时前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在更新我的 Xcode 9,Swift 4,iOS 11和iPhone X的应用程序.它似乎相对平稳,但每当我点击后退按钮时我的应用程序崩溃.我可以毫无问题地前进3-4个屏幕但是第一个后退按钮总是会崩溃应用程序.它不需要模拟器作为iPhone X运行.

它似乎没有陷入我的代码堆栈跟踪,所以这在我看来视图控制器的重绘阶段,我正在弹出,但我不确定.

因为我做了很多自定义绘图,因为在UITableViews和UIViews周围有自定义阴影我在所有位置设置了断点,我将其除以变量,但没有任何东西被击中.因此,似乎不是我的代码用零进行计算.

  1. *** Terminating app due to uncaught exception 'CALayerInvalidGeometry',reason: 'CALayer bounds contains NaN: [nan 0; nan 0]'
  2. *** First throw call stack:
  3. (
  4. 0 CoreFoundation 0x000000010af711cb __exceptionPreprocess + 171
  5. 1 libobjc.A.dylib 0x000000010a8d3f41 objc_exception_throw + 48
  6. 2 CoreFoundation 0x000000010afe5b95 +[NSException raise:format:] + 197
  7. 3 QuartzCore 0x0000000109424424 _ZN2CA5Layer10set_boundsERKNS_4RectEb + 230
  8. 4 QuartzCore 0x0000000109414c29 -[CALayer setBounds:] + 251
  9. 5 UIKit 0x0000000107267439 __27-[_UILabelLayer setBounds:]_block_invoke + 80
  10. 6 UIKit 0x000000010726717b -[_UILabelLayer _setFrameOrBounds:settingAction:] + 23
  11. 7 UIKit 0x00000001072673d8 -[_UILabelLayer setBounds:] + 155
  12. 8 QuartzCore 0x000000010941537c -[CALayer setFrame:] + 630
  13. 9 UIKit 0x0000000107267319 __26-[_UILabelLayer setFrame:]_block_invoke + 80
  14. 10 UIKit 0x000000010726717b -[_UILabelLayer _setFrameOrBounds:settingAction:] + 23
  15. 11 UIKit 0x00000001072672b8 -[_UILabelLayer setFrame:] + 155
  16. 12 UIKit 0x0000000106c4cf1e -[UIView(Geometry) setFrame:] + 368
  17. 13 UIKit 0x0000000106e4ec40 -[UILabel setFrame:] + 141
  18. 14 UIKit 0x0000000106fff254 -[UIButton _layoutTitleView] + 248
  19. 15 UIKit 0x0000000106fff3cf -[UIButton layoutSubviews] + 250
  20. 16 UIKit 0x0000000106c6c551 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1331
  21. 17 QuartzCore 0x000000010941b4ba -[CALayer layoutSublayers] + 153
  22. 18 QuartzCore 0x000000010941f5a9 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
  23. 19 QuartzCore 0x00000001093a81cd _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 365
  24. 20 QuartzCore 0x00000001093d3ae4 _ZN2CA11Transaction6commitEv + 500
  25. 21 UIKit 0x0000000106b97f4a _UIApplicationFlushRunLoopCATransactionIfTooLate + 167
  26. 22 UIKit 0x00000001074ef960 __handleEventQueueInternal + 6894
  27. 23 CoreFoundation 0x000000010af142b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
  28. 24 CoreFoundation 0x000000010afb3d31 __CFRunLoopDoSource0 + 81
  29. 25 CoreFoundation 0x000000010aef8c19 __CFRunLoopDoSources0 + 185
  30. 26 CoreFoundation 0x000000010aef81ff __CFRunLoopRun + 1279
  31. 27 CoreFoundation 0x000000010aef7a89 CFRunLoopRunSpecific + 409
  32. 28 GraphicsServices 0x00000001104e59c6 GSEventRunModal + 62
  33. 29 UIKit 0x0000000106b9dd30 UIApplicationMain + 159
  34. 30 My Customer's Application Name 0x000000010475f087 main + 55
  35. 31 libdyld.dylib 0x000000010cfedd81 start + 1
  36. )
  37. libc++abi.dylib: terminating with uncaught exception of type NSException
TL; DR:在我们的例子中,这个iOS 11 / Xcode 9错误是由将自定义UILabel添加到UINavigationItem.titleView的代码引起的.

这段代码是使用臭名昭着的混合技术 – [UINavigationItem setTitle:]选择器 – 以及调用原始的setTitle:方法编写的,我们的开发人员还使用与UINavigationItem.titleView属性相同的标题设置自定义标签.问题是使用setTitle:nil调用导航项时的情况,以便将空UILabel添加到具有零矩形维度的.titleView中,这导致UIKit崩溃.如果title:参数为nil,立即快速修复是停止设置.titleView.长期解决方案是删除应用程序中的混合.

附:我打开了一个雷达,请求改进此错误错误消息:

Xcode 9: Please improve error handling: -[UILabel setFrame:] and -[CALayer setFrame:] throws unfriendly exception if given a malformed CGRect

猜你在找的Swift相关文章