关于这个主题有很多q / a,其中很多都是指旧版本的iOS。我能找到关于这个主题的最佳答案was this one。
它几乎适用于我,但是当它通过UITabBarViewController子类呈现时,它只能部分工作:我在演示动画期间得到一个漂亮的半透明视图,但是一旦演示动画完成,呈现的VC再次变得不透明
在Objective-C中编码,但我很高兴看到Swift的答案......
- (void)showBusyWithCompletion:(void (^)(BOOL))completion {
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5];
vc.view.opaque = NO;
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:^{
[self performSelector:@selector(hideBusy:) withObject:vc afterDelay:4];
}];
}
- (void)hideBusy:(UIViewController *)vc {
[self dismissViewControllerAnimated:vc completion:nil];
}
同样,呈现VC是一个UITabBarVC子类,除了一些记录访问了哪些标签的代码外,没有做任何事情。所呈现的vc是一个香草视图控制器。它的视图在滑过时显示为透明红色,然后在转换完成后变为不透明的红色(较暗,就像它与黑色混合一样)。
如何在背景出现后保持透明?
答案 0 :(得分:1)
事实证明我上面提到的答案是正确的,我不正确地转录了设置。回顾一下:这不起作用(而另一个答案并未声称它有效):
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
......但其中任何一个都可以:
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
或@TylerTheCompiler指出:
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;