iOS:脚本中使用UIModalPresentationCurrentContext的透明背景模式不工作
我在上看到了许多示例,它们在自定义UIStoryBoardSegue的perform方法中执行相同的操作,以实现具有透明背景的模态,但当我尝试这样做时,一旦动画完成并调用presentViewController,模态的黑色背景会立即返回。代码如下:iOS:脚本中使用UIModalPresentationCurrentContext的透明背景模式不工作,ios,uistoryboard,modalviewcontroller,uistoryboardsegue,uiviewanimationtransition,Ios,Uistoryboard,Modalviewcontroller,Uistoryboardsegue,Uiviewanimationtransition,我在上看到了许多示例,它们在自定义UIStoryBoardSegue的perform方法中执行相同的操作,以实现具有透明背景的模态,但当我尝试这样做时,一旦动画完成并调用presentViewController,模态的黑色背景会立即返回。代码如下: - (void)perform { UIViewController *sourceViewController = self.sourceViewController; UIViewController *destinationV
- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
sourceViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[sourceViewController.view addSubview:destinationViewController.view];
destinationViewController.view.alpha = 0;
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
destinationViewController.view.alpha = 1;
} completion:^(BOOL finished) {
[destinationViewController.view removeFromSuperview];
// boom, the black background returns!
[sourceViewController presentViewController:destinationViewController animated:NO completion:^{
// these have no effect
destinationViewController.view.backgroundColor = [UIColor clearColor];
destinationViewController.view.superview.backgroundColor = [UIColor clearColor];
}];
}];
}
我还通过IB将模式presentationStyle设置为源VC中的当前上下文:
我没有使用UINavigationController
如您所见,我已尝试在sourceViewController和destinationViewController上设置目标视图控制器的背景色、目标视图控制器的superview和setting.modalPresentationStyle,但似乎没有任何效果
如果我注释掉从superview中删除目标视图的部分,以及presentViewController:call,一切正常,但是目标VC被解除锁定,因此我无法与它交互和/或稍后将其展开。在这里真是不知所措
编辑:在走了这条路线之后,我在控制台中看到的另一个问题是对开始/结束外观转换的调用不平衡。错误。已解决:
因此,就我所知,似乎没有办法在perform方法中完全包含透明背景的情况下执行自定义模式segue
解决方案是将我的自定义segue设置为执行中的TransitionLegate,然后在animateTransition:中执行动画。最后,调用[transitionContext CompletTransition:YES];动画完成后
这样做之后,不平衡的调用。。。错误也消失了