我正在使用photoEditing应用程序,我需要在其上添加贴纸,我有一个视图名称是viewImageBackground,在此视图中我有一个图像视图。使用以下代码我在图像视图上添加贴纸。
if selectedPhotos == "Goodies" {
switch indexPath.row {
case 0:
addStickers(#imageLiteral(resourceName: "Goodies-1.png"))
break
case 1:
addStickers(#imageLiteral(resourceName: "Goodies-2.png"))
break
case 2:
addStickers(#imageLiteral(resourceName: "Goodies-3.png"))
break
case 3:
addStickers(#imageLiteral(resourceName: "Goodies-4.png"))
break
default:
break
}
}
添加贴纸功能
func addStickers(_ imgImage: UIImage) {
hideTextButtons()
textView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
textView?.backgroundColor = UIColor.clear
viewImgBackground.addSubview(textView!)
//Content view
gesture = "Stickers"
var imgSticker = UIImageView(frame: CGRect.init(x: 0.0, y: 0.0, width: 80, height: 80))
imgSticker.image = imgImage
imgSticker.contentMode = UIViewContentMode.scaleAspectFill
imgSticker.isUserInteractionEnabled = true
imgSticker.isMultipleTouchEnabled = true
textView?.addSubview(imgSticker)
deleteView = UIImageView(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
deleteView?.backgroundColor = UIColor.clear
deleteView?.image = UIImage(named: "close_gold.png")
deleteView?.isUserInteractionEnabled = true
let singleTap = UITapGestureRecognizer(target: self, action: #selector(self.singleTap))
deleteView?.addGestureRecognizer(singleTap)
textView?.addSubview(deleteView!)
panGesture = UIPanGestureRecognizer.init(target: self, action: #selector(handlePanGesture(_:)))
panGesture.delegate = self
pinchGesture = UIPinchGestureRecognizer.init(target: self, action: #selector(handlePinchGesture(_:)))
pinchGesture.delegate = self
textView?.addGestureRecognizer(panGesture)
textView?.addGestureRecognizer(pinchGesture)
rotateView = UIImageView(frame: CGRect(x: 0, y: (textView?.frame.size.height)! - 25, width: 25, height: 25))
rotateView?.backgroundColor = UIColor.clear
rotateView?.image = UIImage(named: "button_01.png")
rotateView?.isUserInteractionEnabled = true
textView?.addSubview(rotateView!)
let panRotateGesture = UIPanGestureRecognizer(target: self, action: #selector(self.rotateViewPanGesture))
rotateView?.addGestureRecognizer(panRotateGesture)
panRotateGesture.require(toFail: panRotateGesture)
let snapshotImage = UIImage.imageWithView(view: viewImgBackground)
count += 1
logoImages.append(snapshotImage)
}
现在我的观点如下图所示
现在的问题是,我需要使用此代码添加多个贴纸手势我的条件是满意的50%贴纸添加到手势的图像视图但我需要添加多个贴纸,这意味着每当我点击每个贴纸新的imageview与需要添加贴纸,但此代码只会添加一个贴纸并替换贴纸内部视图。我该如何实现呢?
注意:每当我点击重置按钮我需要删除所有这些贴纸,所以你在这里宣布imgSticker作为一个局部变量,这是不值得的所以我该怎么做才能添加多个贴纸图像视图。
请帮助, 谢谢!