AutoLayout: removeFromSuperview / removeConstraints throws exception and crashes hard

后端 未结 13 2206
谎友^
谎友^ 2020-11-27 11:05

We use auto layout constraints selectively, primarily to position labels in relation to editable field elements (UITextView, UITextField, typically). However, since impleme

13条回答
  •  孤城傲影
    2020-11-27 11:28

    To make @smileyborg's awesome answer more actionable:

    This can happen if you have any constraints with multipliers that might suffer from floating point precision issues.

    To solve:

    1. Go over all your constraints that have multipliers (in layout code or by manually editing a storyboard/nib and searching for multiplier=).
    2. If multiplier isn't a "pretty" power of two float, turn it to the nearest one (you can use a floating point calculator)

    To easy way to do 2 is to enter the number you value you want and the calculator and then switch off lower precision bits in the mantissa until the value matches the rounded decimal value at bottom of the calculator.

提交回复
热议问题