【问题标题】:Problems pushing and popping subViews onto the stack将子视图推送和弹出到堆栈的问题
【发布时间】:2017-11-03 10:30:12
【问题描述】:

我正在尝试添加一个需要在堆栈顶部显示的子层 (UINaviationController),它显示得很好,但是当我尝试关闭视图时,我无法让它正常工作,它要么关闭整个 UINavigtioncontroller 并杀死整个堆栈,或者它只是删除我的部分视图并在顶部留下黑屏。

我需要的是让我的 subView 显示在堆栈顶部,并能够在我的委托被调用后从堆栈中弹出它

代码如下

在这里创建子视图

- (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];
}

这就是我试图用来再次关闭子视图的方法,但它们都不起作用

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

我一定错过了什么,但是什么?

【问题讨论】:

    标签: ios objective-c addsubview


    【解决方案1】:

    您需要移除捕获层并隐藏scanRectView

    试试下面的代码:

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

    【讨论】:

    • 很酷,只是隐藏它会在我一遍又一遍地重新创建它时引起问题吗?还是自动为我处理?我的意思是每次按下相机按钮的方法?
    • 实际上我正在将此代码用于二维码。我在scanRectView 中采用了扫描仪布局,所以当扫描完成时,它将隐藏该视图和removeCaptureLayer 从其父视图中
    • 我们在self.view 中添加scanRectView,所以我们想隐藏/删除scanRectView。无需删除self.view
    • 这是从超级层中删除层的正确方法,因为您自己管理它。我首先以为您忘记了对超级实现的一些调用。这也是一个常见的原因。所以也要检查一下。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-19
    • 1970-01-01
    • 2014-09-17
    • 2014-10-02
    相关资源
    最近更新 更多