ConvertRect 没有按预期工作

ConvertRect doesn't work as expected

我正在尝试将深 'Subview' 帧转换为上 'UIView' 帧。我在这里附加视图层次结构。

附上插图:

我试过了,但结果与屏幕相去甚远:

let rect = smallSubview.convert(smallSubview.frame, to: bigSuperview)

我正在尝试将小 'Subview' 框架转换为 'VideoCrop'/bigSuperView 坐标 space。有什么建议么?谢谢!

不确定,但您不应该考虑边界而不是 smallSubView 的框架吗??

我的意思是:

let rect = smallSubview.convert(smallSubview.bounds, to: bigSuperview)

编辑

我无法回答您的评论,因此更新了我的回答:)

快速查看convert API建议

func convert(_ rect: CGRect, to view: UIView?) -> CGRect Description
Converts a rectangle from the receiver’s coordinate system to that of another view.

Parameters

rect A rectangle specified in the local coordinate system (bounds) of the receiver.

view The view that is the target of the conversion operation. If view is nil, this method instead converts to window base coordinates. Otherwise, both view and the receiver must belong to the same UIWindow object.

因为它表明你应该考虑边界而不是框架:)

frame和bounds有什么区别??

Bounds : 指定视图在其自身坐标系中的位置和大小。 Frame:虽然这指定了视图在其 superViews 坐标系中的位置和大小 :)

因此,任何视图的边界都将以 (0,0) 为原点,其中框架的 x 和 y 相对于其父视图 :) 而高度和宽度相同 :)