iOS:ModalView背景透明吗?

dev*_*ost 30 background objective-c modalviewcontroller ios

我想在viewController上显示一个modalview.(有一个导航控制器).

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

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

当我展示它时,那:

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];
Run Code Online (Sandbox Code Playgroud)

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

有人帮我吗?

谢谢,

pan*_*kaj 104

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

对于目标C:

UIViewController *walkThru = [self.storyboard   instantiateViewControllerWithIdentifier:@"WalkThroughScene"];
walkThru.providesPresentationContextTransitionStyle = YES;
walkThru.definesPresentationContext = YES;
[walkThru setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self.navigationController presentViewController:walkThru animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

对于Swift:

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)
Run Code Online (Sandbox Code Playgroud)

你呈现的viewController的backgroundcolor应该是clearColor.


Ton*_*enu 23

您可以查看iOS7示例(请参阅我的通讯),或者您可以简单地试试这个:

从"呈现"方法中删除此行

controller.view.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)

现在,在ShareController添加的viewDidLoad中:

 self.view.backgroundColor = [UIColor clearColor];
 self.modalPresentationStyle = UIModalPresentationCurrentContext;
 self.modalPresentationStyle = UIModalPresentationFormSheet;
Run Code Online (Sandbox Code Playgroud)

PS

如果你有一个navigationController ...使用

[self.navigationController presentViewController:controller animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

  • 这在iOS 8上对我不起作用.动画可以工作,但在视图出现后,它的背景又回到了黑色. (14认同)