NSLayoutConstraint常量不是有限的!这是违法的。恒:INF

问题描述:

后的iOS更新版本10.3.3,错误出现在一些设备,而不是全部。那就是......NSLayoutConstraint常量不是有限的!这是违法的。恒:INF

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSLayoutConstraint constant is not finite! That's illegal. constant:inf firstAnchor:<NSLayoutXAxisAnchor:0x608000679c80 "_UINavigationBarContentView:0x7fce8d57aee0.right"> secondAnchor:<NSLayoutXAxisAnchor:0x608000679d00 "UILayoutGuide:0x6080001be680'UIViewLayoutMarginsGuide'.right">' 
*** First throw call stack: 
(
    0 CoreFoundation      0x0000000110e3126b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x0000000114a67f41 objc_exception_throw + 48 
    2 CoreFoundation      0x0000000110e36402 +[NSException raise:format:arguments:] + 98 
    3 Foundation       0x0000000111a5b749 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193 
    4 Foundation       0x00000001119df92c -[NSLayoutConstraint _setSymbolicConstant:constant:] + 629 
    5 Foundation       0x00000001119df689 -[NSLayoutConstraint setConstant:] + 68 
    6 UIKit        0x0000000112a6dc52 -[UIView _updateLayoutMarginsGuideConstraintsIfNecessary] + 358 
    7 UIKit        0x0000000112a6de5e -[UIView _layoutMarginsDidChangeFromOldMargins:] + 194 
    8 UIKit        0x0000000112a6e849 -[UIView _updateInferredLayoutMarginsFromSuperview:] + 850 
    9 UIKit        0x0000000112a6fc03 -[UIView setSafeAreaInsets:] + 446 
    10 UIKit        0x0000000112a6f2a5 -[UIView _updateSafeAreaInsets] + 125 
    11 UIKit        0x0000000112a9c30e -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1571 
    12 UIKit        0x0000000112adc343 -[UINavigationBar layoutSublayersOfLayer:] + 178 
    13 QuartzCore       0x000000011264cc92 -[CALayer layoutSublayers] + 153 
    14 QuartzCore       0x0000000112650d79 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401 
    15 QuartzCore       0x00000001125d9851 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 385 
    16 QuartzCore       0x00000001126051c2 _ZN2CA11Transaction6commitEv + 500 
    17 QuartzCore       0x0000000112605f14 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76 
    18 CoreFoundation      0x0000000110dd3e57 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 
    19 CoreFoundation      0x0000000110dd3dae __CFRunLoopDoObservers + 430 
    20 CoreFoundation      0x0000000110db83c4 __CFRunLoopRun + 1572 
    21 CoreFoundation      0x0000000110db7b29 CFRunLoopRunSpecific + 409 
    22 GraphicsServices     0x000000011a8dd9c6 GSEventRunModal + 62 
    23 UIKit        0x00000001129ce9a4 UIApplicationMain + 159 
    24 APP NAME       0x000000010f8c1847 main + 55 
    25 libdyld.dylib      0x0000000117f8d621 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

有趣的是,这个错误对所有设备都没有任何意义。有在我的设备(iOS版10.3.3)没有错误

所以我试图在Xcode 9测试版5,iOS的11测试版5上运行这个程序,得到一些错误,并且出现此断言失败。我认为对navigationBarItem有疑问。

请帮忙。

+0

有iOS11和以前的版本之间的差异。事物被弃用。这里有两个链接,可以帮助:https://useyourloaf.com/blog/safe-area-layout-guide/和https://useyourloaf.com/blog/changing-root-view-layout-margins/我敢打赌这是其中之一。理由是:(1)它适用于iOS 10.3.3,这意味着您使用的是Xcode 8.(2)它不适用于iOS 11/Xcode 9 beta 5。祝您好运! – dfd

+0

谢谢dfd。我会看到所有的链接。但是,我在同事的iPhone 7(iOS 10.3.3)中看到了这个错误..所以,我很困惑。 –

+0

我的建议是?按照这个逻辑进行。将“beta”(iOS11,Xcode9)与“当前”分开。消除有用的东西!然后,缩小范围 - 如果它是iOS11,则使用Xcode 9和它非常稳定的模拟器来复制,如果不是,也可以查看是否有任何工作。接下来,使用断点进行调试。 **底线?**如果您感到困惑,您将允许太多变量侵入您的*真实*问题。 (而且,它会越来越多地侵入你的问题。)**缩小事情的范围!**拜托,只因为你在同事的手机上遇到这个错误,并不意味着什么!祝你好运。 – dfd

在我的情况下试图让UITextField.firstRect()时,我得到了一个“无限”的由来一个有效UITextRange。这导致约束更新失败。

我会建议获得的Xcode 9,有调试代码。