xcode 在视图层上方加载子视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8854872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:59:43  来源:igfitidea点击:

Loading subview above view's Layer

iphoneobjective-ciosxcode

提问by Shubhank

I followed a tutorial on taking pictures using AvFoundation Framework.. so i am not proficient in it.. thats one point.

我遵循了使用 AvFoundation Framework 拍照的教程..所以我不精通它..那是一点。

In the app..in the nib. There is a view(SUBVIEW) as a sub view of the main view(MAINVIEW). And there is a an image view and button as a subview of the subview View(SUBVIEW) not the Main view.

在应用程序中……在笔尖中。有一个视图(SUBVIEW)作为主视图(MAINVIEW)的子视图。并且有一个图像视图和按钮作为子视图视图(SUBVIEW)而不是主视图的子视图。

There is code in the tutorial (for the subview)

教程中有代码(针对子视图)

AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];


    [self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];

but after applying this the image view appears in back of the SUBVIEW not in front of it as it was supposed to in the nib.. So how to get image view appear in front of the view..vimagepreview is the SUBVIEW

但是在应用此之后,图像视图出现在 SUBVIEW 的后面,而不是像它应该在笔尖中那样出现在它的前面。

采纳答案by Aaron Hayman

Try creating a new view programmatically, add the layer, and then add the view to the subview.

尝试以编程方式创建一个新视图,添加图层,然后将视图添加到子视图。

AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
UIView *newView = [[UIView alloc] initWithFrame:SUBVIEW.bounds];
[newView.layer addSublayer: captureVideoPreviewLayer];
[SUBVIEW addSubview: newView];

That should make sure the layer is above the subview.

这应该确保该层位于子视图之上。

回答by Mrunal

I guess you require to bring your subview (image view container view) in front.

我猜你需要把你的子视图(图像视图容器视图)放在前面。

Check this out: bringSubViewToFront:

看看这个:带来SubViewToFront:

Its UIView class method.

它的 UIView 类方法。

Let me know whether this works for you or not

让我知道这是否适合您

回答by John Paul Manoza

This will work on both iOS7 and iOS8.

这将适用于 iOS7 和 iOS8。

[videoPreviewLayerParentView.layer insertSublayer:videoPreviewLayer atIndex:0];
[videoPreviewLayerParentView.layer insertSublayer:aboveView.layer atIndex:1];

回答by stumped

Try reordering the z-index:

尝试重新排序 z-index:

//subview to go infront
frontView.layer.zPosition = 100

//layer to go to back
backLayer.zPosition = 0