ios 如何获得底部y坐标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17332622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How get bottom y coordinate
提问by Alessio Vinaccia
How can I get the bottom left coordinate, i.e. the maximum y coordinate, of a view in obj-c and Swift?
如何获得 obj-c 和 Swift 中视图的左下角坐标,即最大 y 坐标?
回答by Gabriele Petronella
Supposing that you're talking about UIView
, you may want to look at the CGGeometry
reference.
假设您正在谈论UIView
,您可能需要查看CGGeometry
参考资料。
Talking about 'left' and y coordinate doesn't make much sense, but for instance
谈论“左”和 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
and so on. You get the idea.
等等。你明白了。
In Swift, this is even more convenient, as you can do
在 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
回答by SeanT
It depends on what you want the coordinate in reference to. If you want the bottom left coordinate in your view's superview you could get the left and bottom with:
这取决于您想要参考的坐标。如果您想要视图的超级视图中的左下角坐标,您可以使用以下命令获得左下角:
view.frame.origin.x
for the left coordinate
view.frame.origin.x
对于左坐标
and
和
view.frame.origin.y + view.frame.size.height
for the bottom coordinate
view.frame.origin.y + view.frame.size.height
对于底部坐标