强制图层不在标签栏中旋转

时间:2016-02-08 12:28:01

标签: ios swift swift2 avfoundation tabbarcontroller

我有一个tabBar应用。其中一个标签有一个AVCaptureVideoPreviewLayer,我在其中显示一个用于读取条形码的相机。旋转屏幕时,所有内容都会旋转(相机栏和相机图像)。我想要的是相机的静态图像(禁用其旋转)和旋转屏幕时旋转的标签栏。

这是我将相机图层添加到tabBar的方式:

override func viewDidLoad() {

    super.viewDidLoad()

    view.backgroundColor = UIColor.blackColor()
    self.captureSession = AVCaptureSession()

    // This object represents a physical capture device and the properties associated with that device
    let videoCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    // Is useful for capturing the data from the input device
    let videoInput: AVCaptureDeviceInput

    do {
        videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
    } catch {
        self.failed();
        return
    }

    if (self.captureSession.canAddInput(videoInput)) {
        self.captureSession.addInput(videoInput)
    } else {
        self.failed();
        return;
    }

    let metadataOutput = AVCaptureMetadataOutput()

    if (self.captureSession.canAddOutput(metadataOutput)) {
        self.captureSession.addOutput(metadataOutput)

        metadataOutput.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())
        metadataOutput.metadataObjectTypes = [AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypePDF417Code,
            AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code,
            AVMetadataObjectTypeCode39Mod43Code, AVMetadataObjectTypeCode93Code,
            AVMetadataObjectTypeCode128Code]
    } else {
        self.failed()
        return
    }

    // Adds the preview layer to display the captured data. Sets the videoGravity to AspectFill so that it covers the full screen
    self.previewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession);
    self.previewLayer.frame = self.view.layer.bounds;
    self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    self.view.layer.addSublayer(self.previewLayer)
    self.captureSession.startRunning();

}

1 个答案:

答案 0 :(得分:0)

停止旋转视图而不是图层。

FilerImage

这应该有用。