I'm developing an augmented reality game, and I ran into the problem of orienting the orientation of the camera when the orientation lock of the device is turned on.
I use this code to load the camera view inside the view:
AVCaptureSession *session = [[AVCaptureSession alloc] init]; AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; captureVideoPreviewLayer.frame = self.sessionView.bounds; [self.sessionView.layer addSublayer:captureVideoPreviewLayer]; CGRect bounds=sessionView.layer.bounds; captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; captureVideoPreviewLayer.bounds=bounds; captureVideoPreviewLayer.orientation = [[UIDevice currentDevice] orientation]; captureVideoPreviewLayer.position=CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds)); AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
And to preserve the orientation of the application in landscape mode, I have only this field in the selected Xcode Summary application, with:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight)); }
When the device has an orientation lock (double-click the Home button, swipe right, tap the orientation icon), the camera will be viewed in the portrait, and the rest of the game will be in the landscape. Is there any way to fix this? From what I read, it is not possible to disable orientation lock when a user opens a game.
source share