如何获得底部y坐标

Ale*_*cia 15 uiview coordinate ios

如何获得obj-c和Swift中视图的左下角坐标,即最大y坐标?

Gab*_*lla 55

假设您正在谈论UIView,您可能需要查看CGGeometry参考.

谈论'左'和y坐标没有多大意义,但是例如

CGRectGetMaxY(view.frame) // will return the bottommost y coordinate of the view
CGRectGetMinX(view.frame) // will return the leftmost x coordinate of the view
Run Code Online (Sandbox Code Playgroud)

等等.你明白了.

在Swift中,这样做更方便

view.frame.maxY // will return the bottommost y coordinate of the view
view.frame.minX // will return the leftmost x coordinate of the view
Run Code Online (Sandbox Code Playgroud)

  • 没错,但这只能在swift中使用 (3认同)
  • 使用`view.frame.maxY`和`view.frame.minX`可以更轻松地实现这一点 (2认同)

Sea*_*anT 13

这取决于你想要参考的坐标.如果你想在视图的超级视图中使用左下角坐标,你可以得到左边和底部:

view.frame.origin.x 对于左坐标

view.frame.origin.y + view.frame.size.height 对于底部坐标