3

Apple の AVCam サンプル アプリを使用しています。

この例では、ビューにビデオを表示するために AVFoundation を使用しています。

AVCam からランドスケープ アプリを作成しようとしていますが、うまくいきません。

画面の向きが変わると、ビデオはビュー上で回転して表示されます。この問題を処理する方法はありますか?

4

3 に答える 3

10

プレビュー レイヤーを作成する場合:

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);
}

それは私のために働いた。

于 2011-07-11T19:19:32.610 に答える
0

プレビューレイヤーの向きと重力の設定を使用していますか?

previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = CGRectMake(0, 0, 480, 300); 
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.orientation =  AVCaptureVideoOrientationLandscapeRight;
previewLayer.automaticallyAdjustsMirroring = YES;
于 2011-06-11T20:51:12.087 に答える
0

宣言する

- (BOOL)shouldAutorotate;

あなたの .h で。

次に、次のようにします。

- (BOOL)shouldAutorotate {
    return NO;
}

あなたの.mで

これにより、強制的に回転しなくなります。

于 2012-10-11T16:47:50.383 に答える