如何在iOS中显示小型模态视图控制器?

时间:2018-06-14 21:55:10

标签: ios uiview uiviewcontroller uikit

我想知道如何以模态方式显示占据视图整体高度的一小部分的小视图控制器。

我创建了一个TestViewController类,其中包含我关注的单个UIButton。在前一个视图控制器中执行某个操作后,将显示此视图控制器,并且仅占整个高度的一小部分。

到目前为止,我已经有了这个代码,它实现了使视图控制器变得更小的目标。并占据特定的大小。

TestViewController *testViewController = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
CGRect frame = CGRectMake(0, self.view.frame.size.height-80.0, self.view.frame.size.width, 80.0);

testViewController.view.frame = frame;

[self addChildViewController:testViewController];
[self.view addSubview:testViewController.view];
[testViewController didMoveToParentViewController:self];

但是,如何配置此视图控制器,以便如果我在视图控制器外部点击,我会收到通知并可以采取行动(即解雇自己)或完全阻止触摸?这可能吗?

我尝试让视图控制器填满整个屏幕,然后使用透明视图来拦截"拦截"在用于显示我的内容的小子视图之外发生的触摸,但是我无法使UIViewController透明,使用清晰的背景导致显示黑色背景。

我目前正在查看modalPresentationStyle属性,但到目前为止似乎没有帮助。

1 个答案:

答案 0 :(得分:0)

要使<body> <!DOCTYPE html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <html> <head> <meta charset="utf-8" /> <link rel="shortcut icon" href="//#" /> </head> <body> <div id="result"> </div> <div class="center"> <table id="fruitsid" class="fruitsclass skillsTable class"> <thead></thead> <tbody></tbody> </table> </div> <div class="center"> <table cellspacing="5" id="carsid" cellspacing="5" class="carsclass pilltable class"> <thead></thead> <tbody></tbody> </table> </div> </body> </html> 透明,您必须提供UIViewController并将ModalViewController的属性设置为modalPresentationStyle

UIModalPresentationOverCurrentContext

ModalViewController *mvc = [[ModalViewController alloc]initWithNibName:@"ModalViewController" bundle:[NSBundle mainBundle]];      mvc.modalPresentationStyle = UIModalPresentationOverCurrentContext;       [self presentViewController:mvc animated:YES completion:nil]; 中,您需要设置ModalViewController清除并设置backgroundcolor false。

opaque

如果您想使self.view.backgroundColor = [UIColor clearColor]; self.view.opaque = false; 透明,请根据您的要求设置ModalViewController和不透明度。

相关问题