Ios 如何得到y坐标

Ios 如何得到y坐标,ios,uiview,coordinate,Ios,Uiview,Coordinate,如何获取obj-c和Swift中视图的左下角坐标,即最大y坐标?假设您正在谈论UIView,您可能需要查看参考 谈论“左”和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 等等。你明白了 在Sw

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

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

谈论“左”和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
等等。你明白了

在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

这取决于您希望坐标参照的对象。如果要在视图的superview中使用左下角坐标,可以使用以下方法获得左下角坐标:

左坐标的视图.frame.origin.x


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

这可以通过
view.frame.maxY
view.frame.minX
实现,这仅在swift中可用,虽然我猜Swift版本应该是minX而不是Minyi如果它是一个子视图,并且您得到了一个错误的值,请尝试它:bounds<代码>查看.bounds.maxY