最后,我找到了一种方法。我所做的是我注意到两个CGPoint
的leftPoint和rightPoint在touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
,下面的方法是使用更新leftPoint和rightPoint
func updatePoints(currentPoint: CGPoint){
if leftPoint.x > currentPoint.x {
leftPoint.x = currentPoint.x
}
if leftPoint.y > currentPoint.y {
leftPoint.y = currentPoint.y
}
if rightPoint.x < currentPoint.x {
rightPoint.x = currentPoint.x
}
if rightPoint.y < currentPoint.y {
rightPoint.y = currentPoint.y
}
}
当终于要拯救签名。我计算的宽度和上述点图像的基础的高度,然后使用CGRect()
let width = rightPoint.x - leftPoint.x
let height = rightPoint.y - leftPoint.y
let rect = CGRect(x: leftPoint.x, y: leftPoint.y, width: width, height: height)
let croppedImage = imageView.image!.cropRect(rect)
如果您有其他的想法,请让我知道裁剪图像!现在我会用这个。谢谢