gpt4 book ai didi

ios - 如何在 iPhone iOS7+ 上创建透明的模态 UIViewController?

转载 作者:行者123 更新时间:2023-11-29 12:28:15 25 4
gpt4 key购买 nike

我有一个相对简单的问题,我似乎无法弄清楚。

我在一个 UIViewController (myViewController) 中,它嵌入在 UIViewController 层次结构中的某处(在父 UITabBarController 下方的某处)。

myViewController 有一个按钮。按下该按钮时,我想用黑色、半透明、模态 UIViewController (myModalViewController) 覆盖整个屏幕(包括来自父 UITabBarController 的所有粘性物质)和其他粘性物质。

如果我只是打电话

[myViewController presentViewController:myModalViewController..]

一旦过渡结束,myViewController 的视觉效果就会消失,从而破坏了半透明覆盖的点。

如果我将 myModalViewController 设置为 myViewController 的 subview Controller 并将 myModalViewController.view 添加为 myViewController.view 的 subview ,则具有半透明黑色背景的模态视图 Controller 将出现在 UITabBarController 的所有按钮下方。这很糟糕,因为我想要覆盖整个屏幕。

因此,相反,我在层次结构中寻找最顶层的 View Controller ,并将 myModalViewController 添加为它的子级:

UIViewController* root = myViewController;
while (root.parentViewController) {
root = root.parentViewController;
}

[root addChildViewController:myModalViewController];
[root.view addSubview:myModalViewController.view];

如果这是处理这种情况的正确方法?看起来很笨拙。

另外,我如何让 myModalViewController 以模态方式运行并吞下所​​有触摸手势,以便它下面的所有 UI 都不响应触摸?现在它确实如此,我所有修复它的尝试都失败了。此外,myModalViewController 及其中的所有 UIView 似乎都没有收到任何触摸通知。

最佳答案

如果你想要透明的 ViewController 你必须使用 UIModalPresentationCustom像这样的……

...
[yourModalCtrl setModalPresentationStyle:UIModalPresentationCustom];
[yourModalCtrl setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self setModalPresentationStyle:UIModalPresentationCurrentContext]; //new
//yourModalCtrl.modalPresentationCapturesStatusBarAppearance = YES;
[self presentViewController: yourModalCtrl animated:Yes completion:completion];

[self presentViewController:....] 或者你的“Presenting controller”是什么...

http://b2cloud.com.au/how-to-guides/invisible-background-modal-view/

更新

为了与 iOS 7 兼容,您需要添加新的 [self setModalPresentationStyle:UIModalPresentationCurrentContext]; - 检查所有代码。此外,您必须设置 animate : No(它与 Yes 一起工作,但您将在控制台中收到一条消息:)

关于ios - 如何在 iPhone iOS7+ 上创建透明的模态 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28443205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com