[英]UIModalPresentationCurrentContext not showing transparent background
[英]iOS: transparent background modal in storyboard using UIModalPresentationCurrentContext not working
我在SO上看到了很多示例,它们在自定义UIStoryBoardSegue
的perform
方法中执行相同的操作,以实现具有透明背景的模态,但是当我尝试执行此操作时,动画结束并调用presentViewController时,模态的黑色背景立即返回。 这是代码:
- (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在源VC中将模式presentationStyle设置为“当前上下文”:
我没有使用UINavigationController
。
如您所见,我尝试设置目标视图控制器的背景色,目标视图控制器的.modalPresentationStyle
视图,在sourceViewController 和 destinationViewController上设置.modalPresentationStyle
,但似乎没有任何效果!
如果我注释掉将目标视图从其presentViewController:
视图中删除的部分以及presentViewController:
调用,则一切正常,但是目标VC被取消了分配,因此我无法与其进行交互和/或稍后对其进行展开。 这里真是茫然。
编辑:走这条路线后,我在控制台中看到的另一个问题是Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x7f86a042c114>.
的Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x7f86a042c114>.
错误。
因此,据我所知,似乎无法执行完全包含在perform
方法中的具有透明背景的自定义模式segue。
解决方案是将我的自定义序列设置为perform
的transitionDelegate
,然后在animateTransition:
进行动画animateTransition:
。 最后,调用[transitionContext completeTransition:YES];
动画结束后。
执行此操作后,“不平衡的呼叫...”错误也消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.