【发布时间】:2021-10-02 00:38:55
【问题描述】:
我有一个 imageView,它的 frame 是 (47.0, 415.66666666666674, 320.0, 320.0),它的 y 原点是 415
lazy var imageView: UIImageView = {
let imgView = UIImageView()
// ...
imgView.contentMode = .aspectScaleFit
}
要在我使用的 imageView 中获取图像的矩形:
view.layoutIfNeeded()
let imageRect = AVMakeRect(aspectRatio: imageView.image!.size, insideRect: imageView.bounds)
print(imageRect) // (-47.0, -358.2753623188407, 320.0, 205.21739130434787)
当我尝试转换 imageRect 以找出它在 Window 坐标系内的位置时,我得到了
let frameInWindow = imageView.convert(imageRect, from: nil)
print(frameInWindow) // (-47.0, -358.2753623188407, 320.0, 205.21739130434787)
我有两个问题:
1- 为什么 x 和 y 的值为负值 -47 和 -358
为了获得正的 y 值,我使用了 let yPosition = abs(frameInWindow.origin.y),这给了我一个 358 的 yPosition,但是它在 imageView 的 y 位置之上。
2-为什么 yPosition 不是 425 或者考虑到图像的中心设置在 imageView 的中心的任何位置,并且因为图像小于 imageView,它的 y.origin 应该低于 415( Window内imageView的y值)
【问题讨论】:
标签: ios swift uiimageview cgrect