如何调整我的UIButton以保持纵横比

时间:2022-04-17 19:43:34

I have made a View Controller on my storyboard and added to buttons to it,

我在故事板上制作了一个View Controller并添加到按钮上,

I am starting a AVCaptureSession on my View Controller's view like this,

我正在我的View Controller的视图上启动AVCaptureSession,

AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;

CALayer *viewLayer = self.view.layer;
NSLog(@"viewLayer = %@", viewLayer);
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

captureVideoPreviewLayer.frame = self.view.layer.bounds;
[self.view.layer addSublayer: captureVideoPreviewLayer];

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
    // Handle the error appropriately.
    NSLog(@"ERROR: trying to open camera: %@", error);
}
[session addInput:input];

[session startRunning];
stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[stillImageOutput setOutputSettings:outputSettings];

[session addOutput:stillImageOutput];

My problem is that my buttons get hidden as the preview layer takes up the whole screen I want the preview layer to assume whole screen but also want to display the buttons for capturing and closing the session

我的问题是我的按钮被隐藏,因为预览图层占据整个屏幕我希望预览图层占据整个屏幕,但也想显示捕获和关闭会话的按钮

How can I go about it?

我该怎么办呢?

1 个解决方案

#1


0  

Try moving your button on top of the view controller views hierarchy with:

尝试使用以下命令在视图控制器视图层次结构上移动按钮:

[self.view sendSubviewToFront:button];

Do it after you've added captureVideoPreviewLayer as sublayer.

在您将captureVideoPreviewLayer添加为子图层后执行此操作。

#1


0  

Try moving your button on top of the view controller views hierarchy with:

尝试使用以下命令在视图控制器视图层次结构上移动按钮:

[self.view sendSubviewToFront:button];

Do it after you've added captureVideoPreviewLayer as sublayer.

在您将captureVideoPreviewLayer添加为子图层后执行此操作。