1
我製作了一款相機應用程序。在肖像模式下,它看起來像這樣: 風景模式下的相機不全屏
但在橫向模式下它不是全屏所以可能是什麼原因?
這裏是takePhoto功能:
@IBAction func takePhoto(sender: AnyObject) {
var imageViewBackground: UIImageView!
self.fullScreenView.hidden = false
self.recordButton.enabled = false
self.takephoto.enabled = false
self.recordButton.hidden = true
self.takephoto.hidden = true
session.startRunning()
// add the AVCaptureVideoPreviewLayer to the view and sets the view in fullscreen
fullScreenView.frame = view.bounds
fullScreenView.layer.addSublayer(videoPreviewLayer)
// add action to fullScreenView
gestureFullScreenView = UITapGestureRecognizer(target: self, action: #selector(ViewController.takePhoto(_:)))
self.fullScreenView.addGestureRecognizer(gestureFullScreenView)
// add action to myView
gestureView = UITapGestureRecognizer(target: self, action: #selector(ViewController.setFrontpage(_:)))
self.view.addGestureRecognizer(gestureView)
if (preview == true) {
if let videoConnection = stillImageOutput!.connectionWithMediaType(AVMediaTypeVideo) {
// code for photo capture goes here...
stillImageOutput?.captureStillImageAsynchronouslyFromConnection(videoConnection, completionHandler: { (sampleBuffer, error) -> Void in
// process the image data (sampleBuffer) here to get an image file we can put in our view
if (sampleBuffer != nil) {
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
let dataProvider = CGDataProviderCreateWithCFData(imageData)
let cgImageRef = CGImageCreateWithJPEGDataProvider(dataProvider, nil, true, CGColorRenderingIntent.RenderingIntentDefault)
let image = UIImage(CGImage: cgImageRef!, scale: 1.0, orientation: UIImageOrientation.Right)
self.fullScreenView.hidden = true
self.fullScreenView.gestureRecognizers?.forEach(self.fullScreenView.removeGestureRecognizer)
self.session.stopRunning()
// save image to the library
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
imageViewBackground = UIImageView(frame: CGRectMake(0, 0, self.width, self.height))
imageViewBackground.image = image
imageViewBackground.tag = self.key
self.view.addSubview(imageViewBackground)
}
})
}
}
else {
preview = true
}
}
請用相關代碼更新問題。你如何啓動相機? –
我發佈了拍照方法 – mafioso