为什么会子视图是由上海华

为什么会子视图是由上海华

问题描述:

删除后的UIViewController viewWillAppear中无法运行

我做的一个子层到一个UIViewController这样为什么会子视图是由上海华

- (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.capture.delegate = self; 

    [self applyOrientation]; 
} 

的问题是,当我删除子我希望自己独到的见解viewWillAppear中运行,但它不是。

我删除这样

[self.capture.layer removeFromSuperlayer]; 

的子层viewWillAppear中不应该当原始View再次出现运行?

如果不是我如何确保我在viewWillAppear中的代码在我移除subLayer时运行?

+0

当您转到另一个控制器并再次返回时,“viewWillAppear”调用。但你只是删除超级层,所以它不叫。 –

+0

你可以这样做..以2个按钮开始并取消。开始将添加图层,当点击取消它将删除图层。 –

建议检查Apple doc了解视图生命周期。 然后你就可以把你的viewWillAppear中的代码在一个新的方法:

-(void)yourFunctionName { 
    //your code here 
} 

,并调用它,你需要的。

但是,也许如果你只是需要更新你的布局,你可以检查setNeedsLayoutlayoutIfNeeded方法。