ios - CALayer - 将子层放在 Storyboard UIButtons 下方?

标签 ios uibutton avfoundation calayer avcapturesession

我的 Storyboard中有一个带有多个 UIButton 的 View Controller 。其中之一激活子层中显示的 AVFoundation 相机预览层:

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

除了预览层呈现在我的按钮之上之外,这工作正常,因此即使按钮仍然可点击,用户也看不到它们。有没有一种简单的方法可以将子层放置在按钮下方?或者在层中提升按钮的简单方法?非常感谢!

最佳答案

按钮层都是主视图层的子层。您需要将相机预览层放在按钮层的下方。试试这个:

// 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];

关于ios - CALayer - 将子层放在 Storyboard UIButtons 下方?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16043130/

相关文章:

swiftui - 显示另一个 swiftUI View 时如何停止相机工作?

ios - 获取数组元素的索引作为 Int

swift - 当默认模式兼容所有类别时,AVAudioSession 中其他模式的用途是什么?

ios - 如何在 Swift 的日期选择器上设置本地通知时间

xcode - “重玩”按钮不起作用

ios - 没有调用目标为 nil 的 UIButton 函数?

ios - 自定义UIButton时不同状态的IBInpectable属性

ios - 如何使用 AVfoundation (swift3) 将照片放在 imageView 上

ios - 如何在快速选择时更改谷歌地图标记颜色?

ios - 如何在 Swift 中动态创建 buttonAction 函数