AVCaptureVideoPreviewLayer smooth orientation rotation

后端 未结 9 923
Happy的楠姐
Happy的楠姐 2021-02-02 16:45

I\'m trying to disable any discernable orientation rotation to an AVCaptureVideoPreviewLayer while still maintaining rotation for any subviews. AVCaptureVideoPreviewLayer does h

9条回答
  •  故里飘歌
    2021-02-02 16:50

    I was able to accomplish this with the following code:

    Set up when you need the camera:

    preview = [[self videoPreviewWithFrame:CGRectMake(0, 0, 320, 480)] retain];
    [self.view addSubview:preview];
    

    The videoPreviewWithFrame function.

    - (UIView *) videoPreviewWithFrame:(CGRect) frame {
      AVCaptureVideoPreviewLayer *tempPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[self captureSession]];
      [tempPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
      tempPreviewLayer.frame = frame;
    
      UIView* tempView = [[UIView alloc] init];
      [tempView.layer addSublayer:tempPreviewLayer];
      tempView.frame = frame;
    
      [tempPreviewLayer autorelease];
      [tempView autorelease];
      return tempView;
    }
    

提交回复
热议问题