如何只保存UIImageView不是我的照片应用程序的整个屏幕。 在Swift中

我的应用程序有一个相机部分。 它拍摄一张照片,然后在照片上加水印。 但是,当保存照片时,整个屏幕将被保存,而不仅仅是UIImageView 。 我只想要保存UIImageView 。 不是那样,而是因为button上的菜单栏不是那么大。 我只是觉得没有图片中的菜单栏会更好。

拍照之前的应用照片: app拍照之前的照片。

如何拍摄照片的照片保存: 如何拍摄照片的照片被保存。

这是我的代码如下。

 import UIKit class Camera: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate { @IBOutlet weak var cameraScreen: UIImageView! var screenView: UIImageView! @IBAction func Camera(_ sender: AnyObject) { if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){ let imagePicker = UIImagePickerController() imagePicker.delegate = self imagePicker.sourceType = UIImagePickerControllerSourceType.camera; imagePicker.allowsEditing = false self.present(imagePicker, animated: true, completion: nil)}} func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject: AnyObject]!){ cameraScreen.image = image self.dismiss(animated: true, completion: nil); screenView = UIImageView() screenView.frame = CGRect(x:0, y: 0, width: self.view.frame.width, height: self.view.frame.height) let text = "Java" let label = UILabel(frame: CGRect(x: 125, y: 400, width: self.view.frame.width, height: 300)) label.font = UIFont(name: label.font.fontName, size: 200) label.textColor = UIColor.blue label.alpha = 0.3 label.text = text self.view.addSubview(screenView) self.view.addSubview(label) // i tried self, nil, nil UIGraphicsBeginImageContext(self.view.frame.size) self.view.drawHierarchy(in: self.view.bounds, afterScreenUpdates: true) let photo = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() UIImageWriteToSavedPhotosAlbum(photo!, nil, nil, nil) } @IBAction func Save(_ sender: AnyObject) { let alert = UIAlertController(title: "Image Saved", message: "", preferredStyle: .alert) let okay = UIAlertAction(title: "OK.", style: .default, handler: nil) alert.addAction(okay) present(alert, animated: true, completion: nil) } }