我想在视图控制器上显示模态视图。 (它有一个导航控制器)。
在我看来,我有文字和一个显示模态视图的按钮。
我创建了一个包含我的模态视图的.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];
我有我的模态视图,但是,背景变成了黑色......我希望看到我视图中的文字。 (我试图设置alpha等等;但是没有运行:'()
有人帮我吗?
谢谢,
您可以查看iOS7示例(请参阅我的通讯),或者您可以简单地试试这个:
从“呈现”方法中删除此行
controller.view.backgroundColor = [UIColor clearColor];
现在,在ShareController
的viewDidLoad中添加:
self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalPresentationStyle = UIModalPresentationFormSheet;
PS
如果你有一个navigationController ...使用
[self.navigationController presentViewController:controller animated:YES completion:nil];
使用以下代码段在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];
对于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的backgroundcolor应该是clearColor。
如果您希望modalVC位于tabbar上,则需要将表示样式定义为UIModalPresentationOverFullScreen
[_presentedViewController setModalPresentationStyle:UIModalPresentationOverFullScreen];
[_presentingViewController presentViewController:_presentedViewController animated:YES completion:nil];
快速回答是你无法呈现透明的模态视图,而不是presentViewController:animated:completion:方法。因为您无法使模态视图控制器透明(您的视图是放置在其上的)。
您可以制作自定义视图,也可以手动设置动画,这是一种创建所需内容的方法。
在PresentingViewController
中,在storyboard segue或IBAction下复制以下代码。
SecondViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"];
//SecondViewController *viewController = [SecondViewController alloc]init]; // if you are adding the viewcontroller programatically
viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[viewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:viewController animated:YES completion:nil];
在第二个ViewController
中,通过故事板或代码执行以下步骤:
这是self.view
颜色,您可以在appDelegate中初始化UIWindow's
颜色。
UIWindow