禁用模式 UIView 后面的 UIView 上的元素
我有一个比超级视图小的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的事情是在“模态”视图后面放置一个带有半透明灰色背景的全屏 UIView。然后它会拦截所有的触摸。它可能看起来像这样:
为了将来参考,您可以设置 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:For future reference, you can set
myView.userInteractionEnabled = NO
to disable touch events on a view.有几种方法可以做到这一点。
如果您有一个具有自定义位置的自定义视图,您可以这样修改它:
创建一个实例
var
:并且每当您需要它时,将其放在自定义视图后面:
当您不再需要它时
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
:And whenever you need it, put it behind your custom view:
When you do not need it anymore