拡張現実ゲームを開発していますが、デバイスの方向ロックがオンになっていると、カメラ ビューの方向に問題が発生しました。
このコードを使用して、ビュー内にカメラ ビューをロードしています。
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];
// device.position ;
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if ([device hasTorch]) {
([device supportsAVCaptureSessionPreset:AVCaptureSessionPreset1280x720]);
}
else {
([device supportsAVCaptureSessionPreset:AVCaptureSessionPreset640x480]);
}
[session addInput:input];
[session startRunning];
また、アプリの向きを横向きに保つために、Xcode アプリの [概要] でそのボックスのみを選択し、次のようにします。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
デバイスの方向ロックがオンになっている場合 (ホーム ボタンをダブルクリックし、右にスワイプし、方向アイコンをタップ)、カメラ ビューは縦向きになり、ゲームの残りの部分は横向きになります。これを修正する方法はありますか?私が読んだことから、ユーザーがゲームを開いたときに方向ロックをオフにすることはできません。