本文介绍了由于未捕获的异常"CALayerInvalidGeometry"而终止应用程序,原因:"CALayer位置包含NaN:[nan nan]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我猜问题始于XCode 10.2.x
当XCode 10.1
崩溃点是下面代码中的"pdfView.frame = self.view.frame
":
The crash point is "pdfView.frame = self.view.frame
" from below code:
import UIKit
import PDFKit
class ViewController: UIViewController {
var pdfView = PDFView()
override func viewDidLoad() {
super.viewDidLoad()
// Prepare document to show
let url = Bundle.main.url(forResource: "sample", withExtension: "pdf")
let pdfDocument = PDFDocument(url: url!)
// PDFView
pdfView = PDFView()
pdfView.frame = self.view.frame
pdfView.autoScales = true
pdfView.document = pdfDocument
// Add PDFView to viewController
self.view.addSubview(pdfView)
}
}
崩溃日志:
2019-05-20 16:24:39.269219+0530 PDFKitDemo[6795:305736] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(
0 CoreFoundation 0x00000001118c06fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010fd63ac5 objc_exception_throw + 48
2 CoreFoundation 0x00000001118c0555 +[NSException raise:format:] + 197
3 QuartzCore 0x00000001149632ae _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 140
4 QuartzCore 0x000000011495268b -[CALayer setPosition:] + 57
5 QuartzCore 0x0000000114952de3 -[CALayer setFrame:] + 560
6 PDFKit 0x00000001106c7097 -[PDFPageLayerTile initWithFrame:forPageLayer:withRenderingTransform:tileContentsScale:generationID:] + 168
7 PDFKit 0x00000001106cc805 -[PDFPageLayer _updateTiles] + 3439
8 PDFKit 0x00000001106c7d8e -[PDFPageLayer setNeedsTilesUpdate] + 87
9 PDFKit 0x00000001106dc97d -[PDFPageView setNeedsTilesUpdate] + 48
10 PDFKit 0x00000001106de816 -[PDFPageView setFrame:] + 334
11 PDFKit 0x00000001106d511c -[PDFDocumentView createPageViewForPageAtIndex:] + 764
12 PDFKit 0x00000001106d6326 -[PDFDocumentView updateVisibility] + 1726
13 PDFKit 0x000000011074576f -[PDFView resizeDisplayView:] + 517
14 PDFKit 0x000000011073ecdf -[PDFView layoutDocumentView] + 464
15 PDFKit 0x000000011073a36a -[PDFView setDocument:waitDuration:] + 1246
16 PDFKitDemo 0x000000010f4833b3 $s10PDFKitDemo14ViewControllerC11viewDidLoadyyF + 2147
17 PDFKitDemo 0x000000010f483874 $s10PDFKitDemo14ViewControllerC11viewDidLoadyyFTo + 36
18 UIKitCore 0x000000011666843b -[UIViewController loadViewIfRequired] + 1183
19 UIKitCore 0x0000000116668868 -[UIViewController view] + 27
20 UIKitCore 0x0000000116ca0c33 -[UIWindow addRootViewControllerViewIfPossible] + 122
21 UIKitCore 0x0000000116ca1327 -[UIWindow _setHidden:forced:] + 289
22 UIKitCore 0x0000000116cb3f86 -[UIWindow makeKeyAndVisible] + 42
23 UIKitCore 0x0000000116c63f1c -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4555
24 UIKitCore 0x0000000116c690c6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1617
25 UIKitCore 0x00000001164ae6d6 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 904
26 UIKitCore 0x00000001164b6fce +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
27 UIKitCore 0x00000001164ae2ec -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
28 UIKitCore 0x00000001164aec48 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 1091
29 UIKitCore 0x00000001164acfba __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 782
30 UIKitCore 0x00000001164acc71 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
31 UIKitCore 0x00000001164b19b6 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 576
32 UIKitCore 0x00000001164b2610 _performActionsWithDelayForTransitionContext + 100
33 UIKitCore 0x00000001164b171d -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
34 UIKitCore 0x00000001164b66d0 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
35 UIKitCore 0x0000000116c679a8 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 514
36 UIKitCore 0x000000011681edfa -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
37 FrontBoardServices 0x000000011cb5b125 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 448
38 FrontBoardServices 0x000000011cb64ed6 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 283
39 FrontBoardServices 0x000000011cb64700 __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 53
40 libdispatch.dylib 0x0000000112c53db5 _dispatch_client_callout + 8
41 libdispatch.dylib 0x0000000112c572ba _dispatch_block_invoke_direct + 300
42 FrontBoardServices 0x000000011cb96146 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
43 FrontBoardServices 0x000000011cb95dfe -[FBSSerialQueue _performNext] + 451
44 FrontBoardServices 0x000000011cb96393 -[FBSSerialQueue _performNextFromRunLoopSource] + 42
45 CoreFoundation 0x0000000111827be1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
46 CoreFoundation 0x0000000111827463 __CFRunLoopDoSources0 + 243
47 CoreFoundation 0x0000000111821b1f __CFRunLoopRun + 1231
48 CoreFoundation 0x0000000111821302 CFRunLoopRunSpecific + 626
49 GraphicsServices 0x0000000119d422fe GSEventRunModal + 65
50 UIKitCore 0x0000000116c6aba2 UIApplicationMain + 140
51 PDFKitDemo 0x000000010f484a6b main + 75
52 libdyld.dylib 0x0000000112cc8541 start + 1
53 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
推荐答案
不是确切原因,但是通过添加方法 viewDidLayoutSubviews
,它解决了崩溃问题.
Don't the exact reason but by adding the method viewDidLayoutSubviews
, it's fixed the crash problem.
现在,工作代码为
override func viewDidLoad() {
super.viewDidLoad()
// Prepare document to show
let url = Bundle.main.url(forResource: "sample", withExtension: "pdf")
let pdfDocument = PDFDocument(url: url!)
// PDFView
pdfView = PDFView()
pdfView.autoScales = true
pdfView.document = pdfDocument
// Add PDFView to viewController
self.view.addSubview(pdfView)
}
override func viewDidLayoutSubviews() {
pdfView.frame = self.view.frame
}
这篇关于由于未捕获的异常"CALayerInvalidGeometry"而终止应用程序,原因:"CALayer位置包含NaN:[nan nan]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!