在图像上添加对象Picker照片显示(swift3)

时间:2017-06-12 02:41:33

标签: ios swift3 camera uiimagepickercontroller xib

以下代码是使用图像选择器拍摄标准照片的代码。我正在开发一款可以遮盖照片的应用。所以我想做的是用一个盒子阻挡一些图像选择器。因此,用户知道他们不应该在该区域上面放置一个框。 Example of image picker with box on it. For a better result when the photo is masked.

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)

    }

1 个答案:

答案 0 :(得分:0)

您可以使用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)
}