如何允许用户在保存之前预览图像,并赋予他们取消功能

问题描述 投票:0回答:1

我正在用它来存储图像:

 var screenshot: UIImage {
  return UIGraphicsImageRenderer(size: bounds.size).image { _ in
   drawHierarchy(in: CGRect(origin: .zero, size: bounds.size), afterScreenUpdates: true)
  }
 }

 UIImageWriteToSavedPhotosAlbum(view.screenshot, nil, nil, nil)

这会将图像保存到照片,但是我想允许用户在保存之前先查看照片,并为他们提供取消的选项。

ios swift uiimage
1个回答
0
投票
extension RPPreviewViewController {

 convenience init(image: UIImage) {
  self.init()

  view = UIImageView(image: image)
  view.isUserInteractionEnabled = true

  let cancel = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 45))
  cancel.setTitleColor(.white, for: UIControl.State.normal)
  cancel.setTitle("Cancel", for: UIControl.State.normal)
  cancel.backgroundColor = UIColor.red
  cancel.addTarget(self, action: #selector(canceled), for: .touchUpInside)

  view.addSubview(cancel)
 }


 @objc func canceled() {
  print("cancel")
 }

}

要使用:

let preview = RPPreviewViewController(image: view.screenshot)
present(preview, animated: true, completion: nil)
© www.soinside.com 2019 - 2024. All rights reserved.