Shubhank
Shubhank

Reputation: 21805

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

Upvotes: 2

Views: 8539

Answers (4)

Mrunal
Mrunal

Reputation: 14118

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

Check this out: bringSubViewToFront:

Its UIView class method.

Let me know whether this works for you or not

Upvotes: 2

stumped
stumped

Reputation: 3293

Try reordering the z-index:

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

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

Upvotes: 0

John Paul Manoza
John Paul Manoza

Reputation: 1735

This will work on both iOS7 and iOS8.

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

Upvotes: 1

Aaron Hayman
Aaron Hayman

Reputation: 8502

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.

Upvotes: 2

Related Questions