简体   繁体   English

CALayer - 将故障板放置在故事板UIButtons下面?

[英]CALayer - Place sublayer below storyboard UIButtons?

I've got a view controller in my storyboard with several UIButtons. 我的故事板中有一个带有几个UIButton的视图控制器。 One of them activates an AVFoundation camera preview layer shown in a sublayer: 其中一个激活子图层中显示的AVFoundation相机预览图层:

captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = self.view.bounds;
[self.view.layer addSublayer:captureVideoPreviewLayer];

This works correctly except for the fact that the preview layer is rendered on top of my buttons so even though the buttons are still clickable they are not able to be seen by the user. 这是正常工作,除了预览图层呈现在我的按钮之上,因此即使按钮仍然可点击,用户也无法看到它们。 Is there an easy way to place the sublayer below the buttons? 有没有一种简单的方法将子图层放在按钮下面? Or an easy way to raise the buttons up in the layer? 或者在图层中提升按钮的简单方法? Thank you much! 非常感谢!

The button layers are all sublayers of the main view's layers. 按钮图层是主视图图层的所有子图层。 You'll need to put your camera preview layer below the button's layers. 您需要将相机预览图层放在按钮的图层下方。 Try this: 尝试这个:

// put it behind all other subviews
[self.view.layer insertSublayer:captureVideoPreviewLayer atIndex:0];

// or, put it underneath your buttons, as long as you know which one is the lowest subview
[self.view.layer insertSublayer:captureVideoPreviewLayer below:lowestButtonView.layer];

Just to add. 只是补充一下。 You can raise any subclass of UIView up in the layer by calling UIView method bringSubviewToFront . 您可以通过调用UIView方法bringSubviewToFront在层中引发 UIView的 任何子类

[self.view bringSubviewToFront:self.desiredButton];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM