What causes this error? “CALayer position contains NaN: [240 nan]”

前端 未结 7 1684
星月不相逢
星月不相逢 2020-12-08 00:41

I\'ve seen this happen whenever i rotate a screen that has a UITableView on it. I\'ve found out that it happens inbetween the willRotate and

7条回答
  •  被撕碎了的回忆
    2020-12-08 01:08

    This error also cost me a long time.
    At the end I found my colleague wrote something like this:

    UIEdgeInsets a;
    a.left = (...some calculation);
    button.imageEdgeInsets = a;
    

    And I rewrote these code like this and fix the issue:

    UIEdgeInsets a;
    a.left = (...some calculation);
    a.top = 0;
    a.bottom = 0;
    a.right = 0;
    button.imageEdgeInsets = a;
    

    some value of UIEdgeInsets isn't initialised properly, and it sometimes turn into a NaN value, and crash the application.
    More generally, you should check whether all values of C-style structs are initialised properly.

提交回复
热议问题