禁用UIView的元素背后模态的UIView [英] disable elements on UIView behind modal UIView

查看:188
本文介绍了禁用UIView的元素背后模态的UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIView是比上海华小,所以我就可以重新present这一观点作为一个按钮被点击时模态的视图。

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

我现在正在试图使后面的UIView的元素不可点击。并且还添加了一个灰色的影子忒我的模态视图的我们那边,以便用户理解模态视图清晰的看法。

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.

我不希望使用presentation模式过渡。我知道,并已在其他项目中实现这一点。
任何帮助是AP preciated。

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

推荐答案

最简单的事情就是打好全屏的UIView 与背后的模式半透明的灰色背景视图。然后,它会拦截所有的触摸。它看起来是这样的:

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

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

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

这篇关于禁用UIView的元素背后模态的UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆