Why does my view move when I set its frame after changing its anchorPoint?

后端 未结 2 830
醉话见心
醉话见心 2020-12-08 12:19

I made two instances of UILabel and added them to my ViewController\'s view. And then I changed the anchorPoint of each from 0.5 to 1.

2条回答
  •  -上瘾入骨i
    2020-12-08 12:58

    Well that is exactly what an anchor point does. Before changing the anchor points, you were setting the frame based of the center of the label. After that, you are setting the frame based on the right bottom corner.

    Since you were only resetting the frame for just one label, one adjusted its frame based on the new anchor point and the other one stayed at the old position.

    If you want them to be at the same point, then you need to reset the frame for both of them after editing the anchor point, OR don't the anchor point at all.

    This guide explains more about anchor points.

提交回复
热议问题