【发布时间】:2018-11-02 13:54:41
【问题描述】:
关于这个话题有很多 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 是一个普通的视图控制器。它的视图在滑过时显示为透明的红色,然后在过渡完成后变为不透明的红色(变暗,就像它与黑色混合)。
背景出现后如何保持透明?
【问题讨论】:
-
你试过
UIModalPresentationOverCurrentContext而不是UIModalPresentationCurrentContext吗? -
回想起来,我意识到我提到的答案有你的建议。我一定是在将最初的内容转录到我的代码时打错了。对不起。
标签: ios iphone uiviewcontroller