ios - Force a layer not to rotate in a tabbar -
i have tabbar app. 1 of tabs has avcapturevideopreviewlayer
, display in camera reading barcodes. when rotate screen, rotate (tabbar , image of camera). static image of camera (disable rotation) , tabbar rotating when rotate screen.
this how add layer of camera tabbar:
override func viewdidload() { super.viewdidload() view.backgroundcolor = uicolor.blackcolor() self.capturesession = avcapturesession() // object represents physical capture device , properties associated device let videocapturedevice = avcapturedevice.defaultdevicewithmediatype(avmediatypevideo) // useful capturing data input device let videoinput: avcapturedeviceinput { 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 preview layer display captured data. sets videogravity aspectfill covers 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(); }
stop rotation of view not layer.
override func shouldautorotate() -> bool { return false } override func supportedinterfaceorientations() -> uiinterfaceorientationmask { return uiinterfaceorientation.portrait.rawvalue }
this should work.
Comments
Post a Comment