I use AVFoundation
framework to capture and display the camera video preview and it works. Now, I want add my own UIImageView
on the top of camera preview, here are some fragments of my code.
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer!.videoGravity = AVLayerVideoGravityResizeAspect
previewLayer!.connection?.videoOrientation = AVCaptureVideoOrientation.Portrait
previewLayer!.frame = previewView.bounds
previewView.layer.addSublayer(previewLayer!)
var imageView : UIImageView
imageView = UIImageView(frame: CGRect(x: 130,y: 320,width: 60,height: 30))
imageView.image = UIImage(named:"scanbutton.png")
previewView.addSubview(imageView)
self.captureSession!.startRunning()
The "scanbutton.png" image file is in the project folder.
The UIImageView
cannot be displayed. Can anyone tell what's wrong, thanks.