请帮我看看如何更改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];
答案 0 :(得分:5)
@property (nonatomic, retain) AVCaptureVideoPreviewLayer *prevLayer;
然后:
self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];
self.prevLayer.frame = yourRect;
[self.view.layer addSublayer: self.prevLayer];
多数民众赞成。