*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]'
今天早上上班萨醒,發(fā)現(xiàn)程序就直接掛了纪铺,昨天調(diào)得好好的檀轨,怎么來(lái)上班就掛了呢悍抑?
棧信息打印如下:
2015-10-20 10:01:12.871 Putaoji[49129:1691777] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]' *** First throw call stack: ( 0 CoreFoundation 0x000000010df49f65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010d244deb objc_exception_throw + 48 2 CoreFoundation 0x000000010df49e9d +[NSException raise:format:] + 205 3 QuartzCore 0x000000010cc2f7e6 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152 4 QuartzCore 0x000000010cc2f959 -[CALayer setPosition:] + 44 5 QuartzCore 0x000000010cc2ffbd -[CALayer setFrame:] + 650 6 UIKit 0x000000010e9673f7 -[UIView(Geometry) setFrame:] + 356 7 UIKit 0x000000010ec50422 -[UIButton _setFrame:deferLayout:] + 125 8 UIKit 0x000000010ec50522 -[UIButton setFrame:] + 178 9 Putaoji 0x000000010ae41132 -[PTJInviteFriendsViewController createShareButtonWithFrame:atIndex:title:imageName:] + 690 10 Putaoji 0x000000010ae4004b -[PTJInviteFriendsViewController setupUI] + 2715 11 Putaoji 0x000000010ae3f5a4 -[PTJInviteFriendsViewController viewDidLoad] + 228 12 UIKit 0x000000010ea59931 -[UIViewController loadViewIfRequired] + 1344 13 UIKit 0x000000010ea5f923 -[UIViewController __viewWillAppear:] + 120 14 UIKit 0x000000010ea8f18a -[UINavigationController _startCustomTransition:] + 1177 15 UIKit 0x000000010ea9e7c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 712 16 UIKit 0x000000010ea9f67d -[UINavigationController __viewWillLayoutSubviews] + 57 17 UIKit 0x000000010ec3763d -[UILayoutContainerView layoutSubviews] + 248 18 UIKit 0x000000010e97f11c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710 19 QuartzCore 0x000000010cc3836a -[CALayer layoutSublayers] + 146 20 QuartzCore 0x000000010cc2cbd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 21 QuartzCore 0x000000010cc2ca4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 22 QuartzCore 0x000000010cc211d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 23 QuartzCore 0x000000010cc4e9f0 _ZN2CA11Transaction6commitEv + 508 24 UIKit 0x000000010e8f853a _afterCACommitHandler + 174 25 CoreFoundation 0x000000010de759d7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 26 CoreFoundation 0x000000010de75947 __CFRunLoopDoObservers + 391 27 CoreFoundation 0x000000010de6b59b __CFRunLoopRun + 1147 28 CoreFoundation 0x000000010de6ae98 CFRunLoopRunSpecific + 488 29 GraphicsServices 0x0000000112b04ad2 GSEventRunModal + 161 30 UIKit 0x000000010e8ce676 UIApplicationMain + 171 31 Putaoji 0x000000010af306ff main + 111 32 libdyld.dylib 0x000000010fe9d92d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
解決方法:
實(shí)際標(biāo)題已經(jīng)很清楚的寫到:>*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 40]'
意思是說(shuō)程序崩潰是CALayer的位置中含有不存在的數(shù),說(shuō)白了就是你的View.frame 中計(jì)算的時(shí)候序无,有的地方除以0了边苹。例如在我的程序中計(jì)算的時(shí)候:
CGFloat leftSpace = 24.0f;
CGFloat width = SCREENWIDTH;
CGFloat itemWH = 80.0-22.0;
NSInteger count = shareTitleArray.count;
CGFloat innerSpace = (width -leftSpace*2 - itemWH *count)/(shareTitleArray.count -1);
for (int i = 0; i<shareTitleArray.count; i++)
{
CGFloat x = leftSpace+i*(innerSpace+itemWH);
CGRect frame = CGRectMake(x, 11, itemWH, itemWH);
[self createShareButtonWithFrame:frame atIndex:i title:shareTitleArray[i] imageName:shareImageArray[i]];
}
仔細(xì)一看沒有什么問題筝蚕,但是如果shareTitleArray數(shù)組中的個(gè)數(shù)為1的情況的下锄列,就會(huì)導(dǎo)致除以0窗慎,從而導(dǎo)致程序崩潰物喷。
總結(jié)一下,如果程序總出現(xiàn)上述崩潰信息遮斥,就是在某個(gè)地方除以0了
峦失。