在图像选择器照片显示上添加对象(swift3)

Add object on image Picker photo display (swift3)

下面的代码是使用图像选择器拍摄标准照片的代码。我正在开发一款可以遮盖照片的应用程序。所以我想做的是用一个盒子挡住一些图像选择器。所以用户知道他们不应该把脸放在上面有盒子的区域。

class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate  {
var currentImageView: UIImageView?
var imagePicker: UIImagePickerController!
let maskView = UIImageView()

@IBOutlet var letImageVIEW: UIImageView!


@IBOutlet var finalImage: UIImageView!
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let image = info[UIImagePickerControllerOriginalImage] as! UIImage
    self.dismiss(animated: true, completion: nil)
    self.currentImageView?.image = image

}
@IBAction func takePhotoLeft(_ sender: Any) {
    self.currentImageView = self.letImageVIEW
    imagePicker =  UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .camera
    present(imagePicker, animated: true, completion: nil)

    }

您可以使用 UIImagePickerController 属性 cameraOverlayView。试试这个。

@IBAction func takePhotoLeft(_ sender: Any) {

    self.currentImageView = self.letImageVIEW
    imagePicker =  UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .camera

    let blockView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: 150))
    blockView.backgroundColor = UIColor.red
    imagePicker.cameraOverlayView = blockView
    imagePicker.showsCameraControls = false

    present(imagePicker, animated: true, completion: nil)
}