如何将视图宽度和高度转换为 CGpoint 坐标?
How to translate View width and height to CGpoint coordinates?
我不熟悉使用 CGPoints 在 Swift 中移动对象。我想知道如果您有一个宽度和高度为 320 的自定义视图,您将如何在 CG 坐标系中找出它的约束。
例如我有一个球对象。如果我设置
ball.center.y = CGFloat(390) //where 390 is some random point
然后y的中心在视图中略高于半点线。我知道左上角是 CGPoint 的 0,0 并且想知道在处理二维坐标时是否有标准坐标系。
您似乎在寻找这份 Apple 文档……https://developer.apple.com/library/content/documentation/General/Conceptual/Devpedia-CocoaApp/CoordinateSystem.html
The default coordinate system has its origin at the upper left of the drawing area, and positive values extend down and to the right from it.
如果您想将视图的中心定位在其父视图的中心……
let superview = view.superview!
view.center = CGPoint(x: superview.bounds.midX, y: superview.bounds.midY)
我不熟悉使用 CGPoints 在 Swift 中移动对象。我想知道如果您有一个宽度和高度为 320 的自定义视图,您将如何在 CG 坐标系中找出它的约束。
例如我有一个球对象。如果我设置
ball.center.y = CGFloat(390) //where 390 is some random point
然后y的中心在视图中略高于半点线。我知道左上角是 CGPoint 的 0,0 并且想知道在处理二维坐标时是否有标准坐标系。
您似乎在寻找这份 Apple 文档……https://developer.apple.com/library/content/documentation/General/Conceptual/Devpedia-CocoaApp/CoordinateSystem.html
The default coordinate system has its origin at the upper left of the drawing area, and positive values extend down and to the right from it.
如果您想将视图的中心定位在其父视图的中心……
let superview = view.superview!
view.center = CGPoint(x: superview.bounds.midX, y: superview.bounds.midY)