禁用模式 UIView 后面的 UIView 上的元素

发布于 2024-10-10 12:26:37 字数 236 浏览 1 评论 0原文

我有一个比超级视图小的 UIView,因此当单击按钮时我可以将此视图表示为模式视图。

我已经设法做到了以下几点: * 在父视图中添加子视图。 * 居中此模态视图

我现在尝试使 UIView 后面的元素不可单击。并且还在模态视图的外侧添加灰色阴影,以便用户了解模态视图是焦点视图。

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

我不想使用演示模式转换。我知道并且已经在其他项目中实现了这一点。 任何帮助表示赞赏。

i have a UIView that is smaller than the superview so i can represent this view as a modal view when a button is clicked.

I have managed to do the following:
* add a subview to the superview.
* centered this modal view

I am now trying to make the elements behind the UIView unclickable. And also add a grey shadow te the ourside of my modal view so that the user understands that the modal view is the view in focus.

I would like to know how to achieve this.

I do not wish to use the presentation modal transition. I know and have already implemented this in other projects.
Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉栀 2024-10-17 12:26:37

最简单的事情是在“模态”视图后面放置一个带有半透明灰色背景的全屏 UIView。然后它会拦截所有的触摸。它可能看起来像这样:

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

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

为了将来参考,您可以设置 myView.userInteractionEnabled = NO 来禁用视图上的触摸事件。

The simplest thing would be to lay a fullscreen UIView with a translucent gray background behind your "modal" view. Then it will intercept all of the touches. It might look something like this:

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

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

For future reference, you can set myView.userInteractionEnabled = NO to disable touch events on a view.

看春风乍起 2024-10-17 12:26:37

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

创建一个实例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];

There are several ways to do it.
If you have a custom view which has custom location, you can modify it like that:

Create an instance var:

UIView* backgroundView;

And whenever you need it, put it behind your custom view:

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];

When you do not need it anymore

   [backgroundView removeFromSuperview];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文