【发布时间】:2019-08-05 21:37:27
【问题描述】:
【问题讨论】:
标签: ios cocoa-touch uilabel
【问题讨论】:
标签: ios cocoa-touch uilabel
为了得到你的标签的精确坐标,你需要将你的标签的坐标系转换为superview的坐标系。您可以使用以下方法执行此操作:
convert(_:to:)
从接收者的坐标转换一个矩形 系统到另一个视图。
声明:
func convert(_ rect: CGRect, to view: UIView?) -> CGRect
用法:
let pos = self.lbl.convert(self.lbl.bounds, to: self.view)
print(pos.origin.x) //prints x position relative to superview
print(pos.origin.y) //prints y position relative to superview
【讨论】: