다음 코드를 사용하여 문제를 해결했습니다. 그 하나의 손가락을 사용하여 이미지를 회전하고 크기를 조정하는 데 도움이됩니다.
func stickerResizeGesture(_ recognizer: UIPanGestureRecognizer) {
let superview = recognizer.view?.superview
stickerContainerView = superview
for element in (superview?.subviews)! {
if element.accessibilityHint == "Main Image" {
imgSticker = element as! UIImageView
}
if element.accessibilityHint == "Delete" {
deleteView = element as? UIImageView
}
if element.accessibilityHint == "Rotate" {
rotateView = element as? UIImageView
}
if element.accessibilityHint == "Resize" {
resizeView = element as? UIImageView
}
}
let touchLocation = recognizer.location(in: stickerContainerView?.superview)
let center = CalculateFunctions.CGRectGetCenter((stickerContainerView?.frame)!)
if recognizer.state == .began {
prevPoint = recognizer.location(in: stickerContainerView?.superview)
//Rotate
deltaAngle = Float(atan2(touchLocation.y - center.y, touchLocation.x - center.x) - CalculateFunctions.CGAffineTrasformGetAngle(self.startTransform))
initialBounds = stickerContainerView?.bounds
initialDistance = CalculateFunctions.CGpointGetDistance(center, point2: touchLocation)
//stickerContainerView?.setNeedsDisplay()
} else if recognizer.state == .changed {
if (stickerContainerView?.bounds.size.width)! < CGFloat(100.0) {
stickerContainerView?.bounds = CGRect(x: (stickerContainerView?.bounds.origin.x)!,
y: (stickerContainerView?.bounds.origin.y)!,
width: (stickerContainerView?.bounds.size.width)!,
height: (stickerContainerView?.bounds.size.width)!)
imgSticker.frame = CGRect(x: 12,
y: 12,
width: (stickerContainerView?.bounds.size.width)! - (resizeView?.frame.width)!,
height: (stickerContainerView?.bounds.size.height)! - (resizeView?.frame.height)!)
resizeView?.frame = CGRect(x: (stickerContainerView?.bounds.size.width)! - (resizeView?.frame.width)!,
y: (stickerContainerView?.bounds.size.height)! - (resizeView?.frame.height)!,
width: (resizeView?.frame.width)!,
height: (resizeView?.frame.height)!)
rotateView?.frame = CGRect(x: 0,
y: (stickerContainerView?.bounds.size.height)! - (rotateView?.frame.height)!,
width: (rotateView?.frame.width)!,
height: (rotateView?.frame.height)!)
deleteView?.frame = CGRect(x: 0,
y: 0,
width: (deleteView?.frame.width)!,
height: (deleteView?.frame.height)!)
} else if (stickerContainerView?.bounds.size.height)! < CGFloat(100.0) {
stickerContainerView?.bounds = CGRect(x: (stickerContainerView?.bounds.origin.x)!,
y: (stickerContainerView?.bounds.origin.y)!,
width: (stickerContainerView?.bounds.size.height)!,
height: (stickerContainerView?.bounds.size.height)!)
imgSticker.frame = CGRect(x: 12, y: 12,
width: (stickerContainerView?.bounds.size.width)! - (resizeView?.frame.width)!,
height: (stickerContainerView?.bounds.size.height)! - (resizeView?.frame.height)!)
resizeView?.frame = CGRect(x: (stickerContainerView?.bounds.size.width)! - (resizeView?.frame.width)!,
y: (stickerContainerView?.bounds.size.height)! - (resizeView?.frame.height)!,
width: (resizeView?.frame.width)!,
height: (resizeView?.frame.height)!)
rotateView?.frame = CGRect(x: 0, y: (stickerContainerView?.bounds.size.height)! - (rotateView?.frame.height)!,
width: (rotateView?.frame.width)!,
height: (rotateView?.frame.height)!)
deleteView?.frame = CGRect(x: 0,
y: 0,
width: (deleteView?.frame.width)!,
height: (deleteView?.frame.height)!)
} else {
let point: CGPoint = recognizer.location(in: stickerContainerView!.superview)
let newHeight = (stickerContainerView?.bounds.size.width)! + CGFloat(point.y - prevPoint.y)
let newWidth = (stickerContainerView?.bounds.size.height)! + CGFloat(point.y - prevPoint.y)
if newHeight < CGFloat(100.0) && newWidth < CGFloat(100.0) {
stickerContainerView?.bounds = CGRect(x: stickerContainerView!.bounds.origin.x,
y: stickerContainerView!.bounds.origin.y,
width: 100.0,
height: 100.0)
} else {
stickerContainerView?.bounds = CGRect(x: stickerContainerView!.bounds.origin.x,
y: stickerContainerView!.bounds.origin.y,
width: newWidth,
height: newHeight)
}
imgSticker.frame = CGRect(x: 12,
y: 12,
width: (stickerContainerView?.bounds.size.width)! - (resizeView?.frame.width)!,
height: (stickerContainerView?.bounds.size.height)! - (resizeView?.frame.height)!)
resizeView?.frame = CGRect(x: (stickerContainerView?.bounds.size.width)! - (resizeView?.frame.width)!,
y: (stickerContainerView?.bounds.size.height)! - (resizeView?.frame.height)!,
width: (resizeView?.frame.width)!,
height: (resizeView?.frame.height)!)
rotateView?.frame = CGRect(x: 0,
y: (stickerContainerView?.bounds.size.height)! - 25,
width: (rotateView?.frame.width)!,
height: (rotateView?.frame.height)!)
deleteView?.frame = CGRect(x: 0,
y: 0,
width: (deleteView?.frame.width)!,
height: (deleteView?.frame.height)!)
prevPoint = recognizer.location(in: stickerContainerView?.superview)
}
// Rotate
let ang: Float = atan2(Float(touchLocation.y - center.y), Float(touchLocation.x - center.x))
let angleDiff = deltaAngle - ang
stickerContainerView?.transform = CGAffineTransform(rotationAngle: -(CGFloat)(angleDiff))
stickerContainerView?.setNeedsDisplay()
} else if recognizer.state == .ended {
prevPoint = recognizer.location(in: stickerContainerView?.superview)
//Rotate
let ang: Float = atan2(Float(touchLocation.y - center.y), Float(touchLocation.x - center.x))
startTransform = (stickerContainerView?.transform)!
// stickerContainerView?.setNeedsDisplay()
}
}