以清晰的背景呈现 UIViewController

Posted

技术标签:

【中文标题】以清晰的背景呈现 UIViewController【英文标题】:Presenting UIViewController with clear background 【发布时间】:2016-06-28 05:23:36 【问题描述】:

我正在为 Kony 应用程序编写 ios FFI 方法。在那,我展示了一个具有清晰背景色的视图控制器。但是,它显示了一个白色背景视图。我没有使用故事板,我只是在代码中设计视图。在newviewcontroller viewdidload中,我将self.view背景色设置为clearcolor。

这是我尝试过的,

NewViewController *newVC = [[NewViewController alloc]init];
newVC.providesPresentationContextTransitionStyle = YES;
newVC.definesPresentationContext = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[KonyUIContext onCurrentFormControllerPresentModalViewController:newVC animated:YES];

我是 KonyUIContext 的新手,我该如何解决这个问题?

谁能帮我解决这个问题?

【问题讨论】:

你在使用故事板吗? @BhavinRamani,不,我只在代码中设计视图。在 newviewcontroller viewdidload 中,我将 self.view 背景颜色设置为 clearcolor 好的。然后请用上述评论编辑您的问题。 @BhavinRamani,已编辑... 尝试 newVC.modalPresentationStyle = UIModalPresentationOverCurrentContext; 【参考方案1】:

试试这个代码...它对我来说非常适合....

MyViewController *modalViewController = [[MyViewController alloc] init];
modalViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;           
[KonyUIContext presentViewController:modalViewController animated:YES completion:nil];

【讨论】:

我正在使用 KonyUIContext..., 而不是 self.modalPresentationStyle,将 newVC.modalPresentationStyle 设置为 UIModalPresentationOverCurrentContext 就可以了【参考方案2】:

试试这个,你只需要设置 backgroundcolor 来清除你的 viewcontroller 视图的颜色。

NewViewController *newVC = [[NewViewController alloc]init];
newVC.view.backgroundColor = [UIColor clearColor];
newVC.providesPresentationContextTransitionStyle = YES;
newVC.definesPresentationContext = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[KonyUIContext onCurrentFormControllerPresentModalViewController:newVC animated:YES];

希望对您有所帮助!

【讨论】:

以上是关于以清晰的背景呈现 UIViewController的主要内容,如果未能解决你的问题,请参考以下文章

UINavigationController - 使用 UIBlurEffect 清除背景

iOS 13 UIViewController 模态演示阴影

弹出 UIViewController

如何以模态方式呈现标准 UIViewController

如果以模态方式呈现,则获取最顶层的 UIViewController

在 indexpath.item 以编程方式呈现 UIViewController(嵌入在 UITabBarController 中)