最後,我找到了一種方法。我所做的是我注意到兩個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)
如果您有其他的想法,請讓我知道裁剪圖像!現在我會用這個。謝謝