gpt4 book ai didi

xcode - Swift:如何将 UIImageView 的缩放区域显示到另一个 UIImageView 中

转载 作者:行者123 更新时间:2023-11-30 10:09:12 25 4
gpt4 key购买 nike

我知道到目前为止我已经写了很多关于此的文章,但这可以解决我的精度问题。我已经看到许多应用程序在可拖动对象的附近显示 UIImageView 的缩放区域,如下面的屏幕截图(Jobnote):

enter image description here

我想知道哪种是获得类似内容的最快且最简单的方法。我猜圆形 View 是一个 UIImageView 但我不知道如何在其中进行缩放。如有任何帮助,我们将不胜感激。谢谢

更新:

是否可以通过使用描述的MagnifierContainerViewMagnifyingGlassView来获得这个here

最佳答案

我做了一些不太相似的事情,弹出一个高分辨率图像的 1:1 预览,you can read about here

简而言之,我有一个peekPreviewSize,它是方形放大预览的边长。然后我可以定义距触摸位置的偏移量:

let offset = ((peekPreviewSize * imageScale) / (imageWidth * imageScale)) / 2

接下来,我计算组件边缘与其包含的图像边缘之间的距离:

let leftBorder = (bounds.width - (imageWidth * imageScale)) / 2

然后,利用触摸点的位置和这两个新值,我可以创建剪辑矩形的标准化 x 原点:

let normalisedXPosition = ((location.x - leftBorder) / (imageWidth * imageScale)) - offset

我对 y 执行相同的操作,并使用这两个标准化值创建一个预览点:

let topBorder = (bounds.height - (imageHeight * imageScale)) / 2
let normalisedYPosition = ((location.y - topBorder) / (imageHeight * imageScale)) - offset
let normalisedPreviewPoint = CGPoint(x: normalisedXPosition, y: normalisedYPosition)

...传递给我的 ForceZoomPreview:

let peek = ForceZoomPreview(normalisedPreviewPoint: normalisedPreviewPoint, image: image!)

我的预览组件现在几乎没有什么工作要做。它在其构造函数中传递了标准化原点(见上图),因此它所需要做的就是使用这些值来设置 ImageView 的 contentsRect :

imageView.layer.contentsRect = CGRect(
x: max(min(normalisedPreviewPoint.x, 1), 0),
y: max(min(normalisedPreviewPoint.y, 1), 0),
width: view.frame.width / image.size.width,
height: view.frame.height / image.size.height)

关于xcode - Swift:如何将 UIImageView 的缩放区域显示到另一个 UIImageView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34016232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com