ios - How to display overlay over AVCaptureVideoPreviewLayer -


i need display image(frame) overlay on avcapturevideopreviewlayer. how can this?

-(void) viewdidappear:(bool)animated {     avcapturesession *session = [[avcapturesession alloc] init];     session.sessionpreset = avcapturesessionpresetphoto;     [session commitconfiguration];      calayer *viewlayer = self.vimagepreview.layer;     nslog(@"viewlayer = %@", viewlayer);      avcapturevideopreviewlayer *capturevideopreviewlayer = [[avcapturevideopreviewlayer alloc] initwithsession:session];      capturevideopreviewlayer.frame = self.vimagepreview.bounds;     [self.vimagepreview.layer addsublayer:capturevideopreviewlayer];      avcapturedevice *device = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo];      nserror *error = nil;     avcapturedeviceinput *input = [avcapturedeviceinput deviceinputwithdevice:device error:&error];     if (!input) {         // handle error appropriately.         nslog(@"error: trying open camera: %@", error);     }     [session addinput:input];      _stillimageoutput = [[avcapturestillimageoutput alloc] init];     nsdictionary *outputsettings = [[nsdictionary alloc] initwithobjectsandkeys: avvideocodecjpeg, avvideocodeckey, nil];     [_stillimageoutput setoutputsettings:outputsettings];      [session addoutput:_stillimageoutput];      [session startrunning];  } 

adding new view on video output layer not work. preview layer appear on top of views.

my view hierarchy:

  • mainview
    • overlayview
    • videooutputview

my frame appears under video output view

i figured out. trick have video scan view it's own view nothing inside (no subviews) , add overlays sibling views (instead of child views).

this solution works within interface builder without having resort programmatically creating views.


Comments

Popular posts from this blog

c++ - End of file on pipe magic during open -

basic authentication with http post params android -

data.table making a copy of table in R -