我正在写一个小应用程序拍摄照片并对其进行修改。可以在拍摄的照片上放置贴纸(图像)。我希望用户能够捏住旋转并拖动贴纸,所以我使用UIImageView来包含图像,以便我可以使用手势功能来修改它。
但问题是,在用户完成修改贴纸后,我怎么能用贴纸保存照片?它们处于不同的视图中,我唯一能想到的就是跟踪贴纸的修改并在用户完成修改后将它们绘制在照片上。有更简单的方法吗?我该怎么办?
func addSticker(name: String)
{
var stickerModView = UIImageView(frame: CGRect(blah blah))
var sticker = UIImage(named:"blah blah.png")
stickerModView.image = sticker
self.view.addSubview(stickerMod)
var tapRec = UITapGestureRecognizer()
var pinchRec = UIPinchGestureRecognizer()
var rotateRec = UIRotationGestureRecognizer()
var panRec = UIPanGestureRecognizer()
pinchRec.addTarget(self, action: Selector("pinchedView:"))
rotateRec.addTarget(self, action: Selector("rotatedView:"))
panRec.addTarget(self, action: Selector("draggedView:"))
tapRec.addTarget(self, action: Selector("tappedView:"))
stickerModView.addGestureRecognizer(pinchRec)
stickerModView.addGestureRecognizer(rotateRec)
stickerModView.addGestureRecognizer(panRec)
stickerModView.userInteractionEnabled = true
stickerModView.multipleTouchEnabled = true
}
答案 0 :(得分:0)
您可以拍摄视图的屏幕截图。有很多examples如何做到这一点。
答案 1 :(得分:0)
添加完整的UIImageView
进行编辑后,您可以尝试使用
let rect : CGRect = CGRect() //Your view size from where you want to make UIImage
UIGraphicsBeginImageContext(rect.size);
let context : CGContextRef = UIGraphicsGetCurrentContext()
self.view.layer.renderInContext(context)
let img : UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
//your image ready to save in img
它可能会帮助你!!