Apple の AVCam サンプル アプリを使用しています。
この例では、ビューにビデオを表示するために AVFoundation を使用しています。
AVCam からランドスケープ アプリを作成しようとしていますが、うまくいきません。
画面の向きが変わると、ビデオはビュー上で回転して表示されます。この問題を処理する方法はありますか?
Apple の AVCam サンプル アプリを使用しています。
この例では、ビューにビデオを表示するために AVFoundation を使用しています。
AVCam からランドスケープ アプリを作成しようとしていますが、うまくいきません。
画面の向きが変わると、ビデオはビュー上で回転して表示されます。この問題を処理する方法はありますか?
プレビュー レイヤーを作成する場合:
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
ローテーションを管理するメソッド:
-(void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
[CATransaction begin];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
} else {
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
}
[CATransaction commit];
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
それは私のために働いた。
プレビューレイヤーの向きと重力の設定を使用していますか?
previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = CGRectMake(0, 0, 480, 300);
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;
previewLayer.automaticallyAdjustsMirroring = YES;
宣言する
- (BOOL)shouldAutorotate;
あなたの .h で。
次に、次のようにします。
- (BOOL)shouldAutorotate {
return NO;
}
あなたの.mで
これにより、強制的に回転しなくなります。