Using convertPoint to get the relative position inside a parent UIView

后端 未结 5 1426
臣服心动
臣服心动 2020-12-07 13:12

I\'ve looked at a dozen SO questions on this topic, and none of the answers have worked for me. Maybe this will help get me back on the right path.

Imagine this set

5条回答
  •  抹茶落季
    2020-12-07 13:56

    Swift 5.2

    You need to call convert from the button, not the superview. In my case I needed width data so I converted the bounds instead of just center point. The code below works for me:

    let buttonAbsoluteFrame = button.convert(button.bounds, to: self.view)
    

提交回复
热议问题