[英]how to add a image to camera overlay view (swift4)
My code right here displays a red line on the top of the imagePicker when taking a photo. 此处的我的代码在拍摄照片时在imagePicker的顶部显示一条红线。 I want to do the same thing but add a image in the middle of the red line. 我想做同样的事情,但是在红线中间添加一个图像。 See pic. 见图片。 I added the word image in a yellow box as a example of what I am trying to code. 我在一个黄色框中添加了单词image作为我要编写代码的示例。
@IBAction func takePhoto(_ sender: UIButton) {
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera
present(imagePicker, animated: true, completion: nil)
let mainView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height-150))
let blockView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: 150))
blockView.backgroundColor = UIColor.red
mainView.addSubview(blockView)
imagePicker.cameraOverlayView = mainView
}
Just do: 做就是了:
let frame = CGRect.init(x: 0, y: 0, width: self.view.frame.size.width, height: 150)
let blockView = UIImageView.init(frame: frame)
blockView.contentMode = .scaleAspectFit
blockView.image = UIImage(named: "NameOfYourImage") // Just an example.
See UIImageView
. 参见UIImageView
。
The frame
above needs adjustment of course, to allow for top and bottom margins you show in your screenshot. 当然,上面的frame
需要调整,以允许您在屏幕快照中显示的上边距和下边距。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.