以下代码是使用图像选择器拍摄标准照片的代码。我正在开发一款可以遮盖照片的应用。所以我想做的是用一个盒子阻挡一些图像选择器。因此,用户知道他们不应该在该区域上面放置一个框。
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)
}
答案 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)
}