簡體   English   中英

如何將圖像添加到相機疊加視圖(swift4)

[英]how to add a image to camera overlay view (swift4)

此處的我的代碼在拍攝照片時在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
}

在此處輸入圖片說明

做就是了:

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需要調整,以允許您在屏幕快照中顯示的上邊距和下邊距。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM