gpt4 book ai didi

ios - 如何将图像添加到相机覆盖 View (swift4)

转载 作者:行者123 更新时间:2023-12-04 03:07:20 26 4
gpt4 key购买 nike

我这里的代码在拍照时会在 imagePicker 的顶部显示一条红线。我想做同样的事情,但在红线的中间添加一个图像。见图。我在黄色框中添加了图像一词作为我尝试编码的示例。

    @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
}

enter image description here

最佳答案

只是做:

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.

参见 UIImageView .

当然,上面的 frame 需要调整,以允许您在屏幕截图中显示的顶部和底部边距。

关于ios - 如何将图像添加到相机覆盖 View (swift4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47717096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com