Search code examples
iosobjective-caddsubview

Problems pushing and popping subViews onto the stack


I am trying to add a sublayer that needs to be shown on top of a stack (UINaviationController), it shows up fine as it should but when I try and dismiss the view I cannot get it working properly, it either dismisses the entire UINavigtioncontroller and kills the entire stack or it simply removes parts of my views and leaves a black screen on top.

What I need is for my subView to show on top of the stack and to be able to POP it from the stack after my delegate is called

The code looks as follows

Creating the subviews here

- (IBAction)transactionListViewCameraBtn_Pressed:(id)sender {

    if([NWTillHelper isDebug] == 1) {
        NSLog(@"%s entered", __PRETTY_FUNCTION__);
    }

    self.capture = [[ZXCapture alloc] init];
    self.capture.camera = self.capture.back;
    self.capture.focusMode = AVCaptureFocusModeContinuousAutoFocus;

    [self.view.layer addSublayer:self.capture.layer];


    [self.view bringSubviewToFront:self.scanRectView];
    [self.view bringSubviewToFront:self.decodedLabel];

    self.capture.delegate = self;

    [self applyOrientation];
}

and this is what I have tried to use to dismiss the subView again but none of them works

[self.view removeFromSuperview];
//[self dismissViewControllerAnimated:YES completion:nil];
//[[self navigationController] popViewControllerAnimated:YES];
//[self removeFromParentViewController];

I must be missing something but what?


Solution

  • you need to remove capture layer and hide the scanRectView.

    try with this below code :

    self.scanRectView.hidden = YES;
    [self.capture.layer removeFromSuperlayer];