Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Force a layer not to rotate in a tabbar

I have a tabBar app. One of the tabs has a

AVCaptureVideoPreviewLayer
, I display in it a camera for reading barcodes. When I rotate the screen, everything rotate (tabbar and image of the camera). What I would like to get is a static image of the camera (disable its rotation) and a tabbar rotating when I rotate the screen.

This is how I add the layer of the camera to the 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();

}

iOS 9.2.1

Posted on Feb 8, 2016 5:58 AM

Reply

There are no replies.

Force a layer not to rotate in a tabbar

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.