通过UIModalPresentationFormSheet阻止点击显示另一个视图的视图

时间:2013-07-11 13:08:32

标签: ios objective-c ios6 uiviewcontroller modalviewcontroller

我有一个视图通过

呈现另一个视图
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[weakSelf presentViewController:navigationController animated:YES completion:^{}];

唯一的问题是,呈现该新视图的“主”视图具有可触摸的按钮,因为ModalPresentationFormSheet不占用全屏。我想保留这种格式,但在呈现模态时阻止点击。我知道我可以对每个可能的按钮进行检查,但我确信还有另一种方法!

    if (![weakSelf presentedViewController]) 

谢谢!

2 个答案:

答案 0 :(得分:0)

你可以把"新视图"作为另一个全屏幕视图的子视图,并使其成为"父视图"背景颜色以清除颜色,以便您可以看到"主视图"另外。
现在你无法点击按钮,因为你实际上是点击了父母视图"新视图"

答案 1 :(得分:0)

一种方法可能是放置一个看不见的“盾牌”。在托管视图控制器上方,但在表单下方。

基本上,创建一个背景颜色清晰的空UIView。在您拨打电话之前,将其作为子视图添加到您的演示视图控制器:

[weakSelf presentViewController:navigationController animated:YES completion:^{}];

现在,这并不一定意味着这样的解决方案具有良好的品味。也就是说,表格样式并不意味着以这种方式排他,如果上面安装的UIView是清楚的,它可能会令人困惑。因此,您可以减少该视图上的alpha值以将其变为调光屏幕,以帮助用户了解表单是他们当时唯一可以与之交互的内容:

UIView *dimmingScreen = [[UIView alloc] initWithFrame:self.view.bounds];
dimmingScreen.alpha = 0.5; // play with this value to get different degrees of dimming
dimmingScreen.backgroundColor = [UIColor blackColor]; // play with different colors
[self.view addSubview:dimmingScreen]; 

// Now present your form sheet, as you were:
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[weakSelf presentViewController:navigationController animated:YES completion:^{}];

您也希望能够移除调光屏幕,因此最好使其成为您可以访问的视图控制器属性,以便在需要时删除。