Why does iOS auto layout lead to apparent rounding errors on pre-Retina displays (unit test included)

前端 未结 1 1934
执笔经年
执笔经年 2021-01-01 22:47

I\'m currently having a hard time understanding why the following unit test fails on an iPad 2. Auto layout seems to slightly (by 0.5 points) mis-position view

相关标签:
1条回答
  • 2021-01-01 23:13

    What you've shown is that autolayout abhors misaligned views. On non-retina devices the closest pixel is the nearest point, so it rounds to whole numbers. On retina screens the closest pixel is the nearest half point, so it rounds to the nearest .5. You can demonstrate this by changing y in your second test to 950.25 and noting that view.frame remains {{0, 950.5}, {768, 8}} (instead of changing to {{0, 950.25}, {768, 8}}).

    (Just to prove that it is rounding and not ceiling, if you change y to 950.2 view.frame becomes {{0, 950}, {768, 8}}.)

    0 讨论(0)
提交回复
热议问题