6

请帮助我如何更改 AVCaptureVideoPreviewLayer 帧大小和

我路过Height =100px ; and width = 300px

如果我通过高度大小 100 而不是宽度不会更改为 300px

这是代码:

    AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
    previewLayer.frame = CGRectMake(20, 50, 300, 100);
    self.view.frame=CGRectMake(20, 50, 300, 100);


    CGRect layerRect = [[[self view] layer] bounds];
    [previewLayer setBounds:layerRect];
    [previewLayer setPosition:CGPointMake(CGRectGetMidX(layerRect),CGRectGetMidY(layerRect))];
    [[[self view] layer] addSublayer:previewLayer];
    [previewView.layer addSublayer:previewLayer];
4

1 回答 1

5
@property (nonatomic, retain) AVCaptureVideoPreviewLayer *prevLayer;

然后:

self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];
    self.prevLayer.frame = yourRect;
[self.view.layer addSublayer: self.prevLayer];

而已。

于 2013-08-22T13:31:25.213 回答