3

我的代码在拍照时会在 imagePicker 的顶部显示一条红线。我想做同样的事情,但在红线中间添加一个图像。见图。我在黄色框中添加了单词 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
}

在此处输入图像描述

4

1 回答 1

2

做就是了:

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上面需要调整,以允许您在屏幕截图中显示顶部和底部边距。

于 2017-12-08T15:53:27.407 回答