Shubhank Shubhank - 25 days ago 7
iOS Question

Loading subview above view's Layer

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

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.

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

Answer

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.