【问题标题】:NSLayoutConstraint constant is not finite! That's illegal. constant:infNSLayoutConstraint 常量不是有限的!那是违法的。常数:inf
【发布时间】:2017-08-10 00:46:43
【问题描述】:

iOS 更新版本 10.3.3 后,部分设备出现了 bug,并非全部。那就是..

*** 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 beta 5、iOS 11 beta 5 中运行这个应用程序,但出现了一些错误并出现了这个断言失败。我觉得navigationBarItem有疑问。

请帮忙。

【问题讨论】:

  • iOS11 与之前版本存在差异。东西被弃用了。这里有两个可能有帮助的链接:useyourloaf.com/blog/safe-area-layout-guideuseyourloaf.com/blog/changing-root-view-layout-margins 我敢打赌它就是其中之一。原因:(1) 它适用于 iOS 10.3.3,这意味着您使用的是 Xcode 8。(2) 它不适用于 iOS 11 / Xcode 9 beta 5。祝你好运!
  • 感谢 dfd。我会看到所有的链接。但是,我在同事的 iPhone 7 (iOS 10.3.3) 中看到了这个错误.. 所以,我很困惑..
  • 我的建议?从逻辑上讲。将“beta”(iOS11、Xcode9)与“当前”分开。消除有效的方法!然后,缩小范围 - 如果是 iOS11,请使用 Xcode 9 和它的模拟器,它们非常稳定,如果没有也可以复制,看看是否有任何效果。接下来,使用断点进行调试。 底线?如果您感到困惑,那么您允许太多变量侵入您的真正问题。 (而且,它对您的问题的影响超出了应有的范围。)缩小范围! 请您,仅仅因为您在同事的手机上收到此错误,这没有任何意义!祝你好运。
  • 非常感谢 dfd。 :)

标签: ios uinavigationbar lldb


【解决方案1】:

在我的情况下,当我尝试获取 UITextField.firstRect() 时,我得到了有效 UITextRange 的“无限”原点。这导致约束更新失败。

我建议您获取 Xcode 9 并在那里调试您的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    相关资源
    最近更新 更多