Xcode 9/iOS 11"CALayer界限包含NaN:[nan 0;nan 0]"当使用嵌套的UINavigationController和UITabBarController弹出视图控制器时 [英] Xcode 9 / iOS 11 "CALayer bounds contains NaN: [nan 0; nan 0]" when popping view controller with nested UINavigationController and UITabBarController
问题描述
我正在为Xcode 9,Swift 4,iOS 11和iPhone X更新我的应用程序.它似乎一直相对平稳,但是每当我按下后退按钮时,我的应用程序就会崩溃.我可以前进3-4个屏幕而没有任何问题,但是第一个后退按钮总是使应用程序崩溃.不需要模拟器就可以作为iPhone X运行.
I am updating my application for Xcode 9, Swift 4, iOS 11 and the iPhone X. It seems to go relatively smooth all the way but whenever I hit the back button my application crashes. I can go forward 3-4 screens without any problem but the first back button crashes the application, always. It doesn't require the simulator to run as an iPhone X.
它似乎没有浸入堆栈跟踪中的代码中,所以我认为这是我弹出的视图控制器的重绘阶段.
It doesn't seem to dip into my code in the stack trace so this is in my opinion the redraw phase of the view controller I'm popping to but I'm not sure.
由于我做了很多自定义绘图,因为在UITableViews和UIViews周围有自定义阴影,因此我在除以变量的所有位置都设置了断点,但是没有遇到任何问题.因此似乎不是我的代码以零进行计算.
Since I do quite a bit of custom drawing because there are custom shadows around UITableViews and UIViews I set up breakpoints in all locations where I divide by a variable, but nothing gets hit. So it doesn't seem to be my code that does the calculation by zero.
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [nan 0; nan 0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010af711cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010a8d3f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010afe5b95 +[NSException raise:format:] + 197
3 QuartzCore 0x0000000109424424 _ZN2CA5Layer10set_boundsERKNS_4RectEb + 230
4 QuartzCore 0x0000000109414c29 -[CALayer setBounds:] + 251
5 UIKit 0x0000000107267439 __27-[_UILabelLayer setBounds:]_block_invoke + 80
6 UIKit 0x000000010726717b -[_UILabelLayer _setFrameOrBounds:settingAction:] + 23
7 UIKit 0x00000001072673d8 -[_UILabelLayer setBounds:] + 155
8 QuartzCore 0x000000010941537c -[CALayer setFrame:] + 630
9 UIKit 0x0000000107267319 __26-[_UILabelLayer setFrame:]_block_invoke + 80
10 UIKit 0x000000010726717b -[_UILabelLayer _setFrameOrBounds:settingAction:] + 23
11 UIKit 0x00000001072672b8 -[_UILabelLayer setFrame:] + 155
12 UIKit 0x0000000106c4cf1e -[UIView(Geometry) setFrame:] + 368
13 UIKit 0x0000000106e4ec40 -[UILabel setFrame:] + 141
14 UIKit 0x0000000106fff254 -[UIButton _layoutTitleView] + 248
15 UIKit 0x0000000106fff3cf -[UIButton layoutSubviews] + 250
16 UIKit 0x0000000106c6c551 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1331
17 QuartzCore 0x000000010941b4ba -[CALayer layoutSublayers] + 153
18 QuartzCore 0x000000010941f5a9 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
19 QuartzCore 0x00000001093a81cd _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 365
20 QuartzCore 0x00000001093d3ae4 _ZN2CA11Transaction6commitEv + 500
21 UIKit 0x0000000106b97f4a _UIApplicationFlushRunLoopCATransactionIfTooLate + 167
22 UIKit 0x00000001074ef960 __handleEventQueueInternal + 6894
23 CoreFoundation 0x000000010af142b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x000000010afb3d31 __CFRunLoopDoSource0 + 81
25 CoreFoundation 0x000000010aef8c19 __CFRunLoopDoSources0 + 185
26 CoreFoundation 0x000000010aef81ff __CFRunLoopRun + 1279
27 CoreFoundation 0x000000010aef7a89 CFRunLoopRunSpecific + 409
28 GraphicsServices 0x00000001104e59c6 GSEventRunModal + 62
29 UIKit 0x0000000106b9dd30 UIApplicationMain + 159
30 My Customer's Application Name 0x000000010475f087 main + 55
31 libdyld.dylib 0x000000010cfedd81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
推荐答案
TL; DR::在我们的案例中,此iOS 11/Xcode 9错误是由添加自定义 UILabel的代码引起的
到 UINavigationItem.titleView
.
TL;DR: In our case this iOS 11 / Xcode 9 error was caused by the code that added custom UILabel
to the UINavigationItem.titleView
.
此代码是使用臭名昭著的混淆技术编写的,该技术覆盖了-[UINavigationItem setTitle:]
选择器-以及调用原始的 setTitle:
方法,我们的开发人员还设置了自定义标签与 UINavigationItem.titleView
属性具有相同的标题.问题在于使用 setTitle:nil
调用导航项,从而将空的 UILabel
添加到具有零矩形的 .titleView
中的情况.尺寸,这导致UIKit崩溃.立即的快速解决方案是,如果 title:
参数为nil,则停止设置 .titleView
.长期的解决方法是从应用程序中消除烦恼.
This code was written using notorious swizzling technique that overrode -[UINavigationItem setTitle:]
selector - along with calling the original setTitle:
method our developer also set the custom label with the same title to the UINavigationItem.titleView
property. The problem was the case when the navigation item was called with setTitle:nil
so that empty UILabel
was added to the .titleView
with zero-rect dimensions and this caused UIKit to crash. The immediate quick fix was to stop setting the .titleView
if the title:
argument was nil. The long-term fix will be to remove swizzling from the app.
P.S.我已打开雷达,要求改善此错误的错误消息:
P.S. I have opened a radar with a request to improve the error message for this error:
Xcode 9:请改进错误处理:-[UILabel setFrame:]和-[CALayer setFrame:]如果给出了格式错误的CGRect,则会抛出不友好的异常
这篇关于Xcode 9/iOS 11"CALayer界限包含NaN:[nan 0;nan 0]"当使用嵌套的UINavigationController和UITabBarController弹出视图控制器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!