我的Uiview小于Supperiew,因此当单击按钮时,我可以将此视为表示为模态视图。

我已经设法执行以下操作: *将一个子视图添加到Supperiew。 *以这种模态为中心

我现在正在尝试使uiview无法拼凑的元素。还要添加一个灰色的阴影te我的模态视图的旁边,以便用户了解模态视图是焦点的视图。

我想知道如何实现这一目标。

我不希望使用演示模式过渡。我知道并已经在其他项目中实现了这一点。任何帮助都将受到赞赏。

有帮助吗?

解决方案

最简单的是放置全屏 UIView 在“模态”视图后面具有半透明的灰色背景。然后,它将拦截所有触摸。看起来像这样:

UIView *dimBackgroundView = [[UIView alloc] initWithFrame:theSuperview.bounds];
dimBackgroundView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:.5f];

[theSuperview addSubview:dimBackgroundView];
[theSuperview addSubview:modalView];

供将来参考,您可以设置 myView.userInteractionEnabled = NO 在视图中禁用触摸事件。

其他提示

有几种方法可以做到。如果您有具有自定义位置的自定义视图,则可以像这样修改:

创建一个实例 var:

UIView* backgroundView;

每当您需要时,将其放在您的自定义视图后面:

if (backgroundView == nil)
        backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width)];
backgroundView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:.5f];
[self.view addSubview:backgroundView];
[backgroundView animateBump:customView.view];
[backgroundView addSubview:customView.view];

当您不再需要它

   [backgroundView removeFromSuperview];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top