[英]CALayer - Place sublayer below storyboard UIButtons?
我的故事板中有一个带有几个UIButton的视图控制器。 其中一个激活子图层中显示的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];
只是补充一下。 您可以通过调用UIView方法bringSubviewToFront在层中引发 UIView的 任何子类 。
[self.view bringSubviewToFront:self.desiredButton];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.