Ios 处于横向模式的摄像头未处于全屏模式

Ios 处于横向模式的摄像头未处于全屏模式,ios,swift,camera,fullscreen,Ios,Swift,Camera,Fullscreen,我做了一个相机应用程序。在纵向模式下,它看起来如下所示: 但是在横向模式下,它不是全屏的,那么原因是什么呢 以下是拍照功能: @IBAction func takePhoto(sender: AnyObject) { var imageViewBackground: UIImageView! self.fullScreenView.hidden = false self.recordButton.enabled = false

我做了一个相机应用程序。在纵向模式下,它看起来如下所示:

但是在横向模式下,它不是全屏的,那么原因是什么呢

以下是拍照功能:

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

旋转设备时,视图将根据设备方向进行调整。在您的情况下,当您添加
videoPreviewLayer
时,它将无法正确调整大小。你必须自己做


旋转设备时,更改视频预览层的帧。或者在旋转设备时再次调用该方法。

请使用相关代码更新问题。你是如何启动相机的?我发布了拍照方法,你知道在哪里设置视频预览播放器的框架吗?