gpt4 book ai didi

iOS : ModalView with background transparent?

转载 作者:IT王子 更新时间:2023-10-29 07:47:54 26 4
gpt4 key购买 nike

我想在 viewController 上显示模态视图。 (它有一个导航 Controller )。

在我看来,我有文本和一个显示模态视图的按钮。

我创建了一个包含我的模态视图的 .xib(它是一个带有图像和标签的 View )。

当我展示它时:

ShareController *controller =  [[ShareController alloc] initWithNibName:@"ShareController" bundle: nil];
controller.view.backgroundColor = [UIColor clearColor];
controller.modalPresentationStyle = UIModalPresentationFormSheet;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentViewController:controller animated:YES completion:nil];

我有我的模态视图,但是,背景变黑了..我想在我的 View 中始终看到文本。 (我试图设置 alpha 等。但没有运行 :'( )

有人帮我吗?

谢谢,

最佳答案

使用以下代码片段在 iOS 8 及更高版本上执行此操作:

对于 Objective-C :

UIViewController *walkThru = [self.storyboard   instantiateViewControllerWithIdentifier:@"WalkThroughScene"];
walkThru.providesPresentationContextTransitionStyle = YES;
walkThru.definesPresentationContext = YES;
[walkThru setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self.navigationController presentViewController:walkThru animated:YES completion:nil];

对于 Swift 2:

let viewController : XYZViewController =     self.storyboard!.instantiateViewControllerWithIdentifier(“XYZIdentifier”) as! XYZViewController
viewController.providesPresentationContextTransitionStyle = true
viewController.definesPresentationContext = true
viewController.modalPresentationStyle=UIModalPresentationStyle.OverCurrentContext
self.presentViewController(viewController, animated: true, completion: nil)

对于 Swift 4:

let viewController =  self.storyboard!.instantiateViewController(withIdentifier:  "XYZIdentifier") as! XYZViewController
viewController.providesPresentationContextTransitionStyle = true
viewController.definesPresentationContext = true
viewController.modalPresentationStyle = .overCurrentContext
self.present(viewController, animated: true, completion: nil)

并且您呈现的 viewController 的背景颜色应该是 clearColor。

关于iOS : ModalView with background transparent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21760698/

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