简体   繁体   English

捕获透明UIView上的触摸

[英]Capturing touches on transparent UIView

I have an app that has a series of custom modal dialog views. 我有一个具有一系列自定义模式对话框视图的应用程序。 Being modal I need to prevent users from interacting with items that are to the side of the dialogs (eg when the pause dialog appears I don't want users to be able to touch the buttons to navigate through the app). 作为模态,我需要防止用户与对话框侧面的项目进行交互(例如,当出现暂停对话框时,我不希望用户能够触摸按钮来浏览应用程序)。 To make them modal I have a transparent UIView "behind" each of the dialog views to trap touches. 为了使它们具有模式性,我在每个对话框视图的“后面”都有一个透明的UIView来捕获触摸。 This works fine except that there's a UIView animation that fades the dialogs up and while they're fading up the dialog views ignore touches. 效果很好,除了有一个UIView动画可以淡化对话框,而在淡入对话框时,对话框视图则忽略触摸。

As far as I can tell the problem is that if a UIView 's alpha is not equal to 1.0 then it ignores touches. 据我所知,问题是,如果UIView的alpha不等于1.0,那么它将忽略触摸。 Is there any way to have UIView with some alpha blending respond to touches? 有什么办法可以让带有一些alpha混合的UIView响应触摸?

如果要为对话框视图的Alpha设置动画,并且希望对话框视图在动画过程中支持交互,则在创建动画时需要使用UIViewAnimationOptionAllowUserInteraction选项。

The UIView doesn't ignore touches unless its alpha is 0.0, or if its 'hidden' property is set to YES. UIView不会忽略触摸,除非其alpha为0.0,或者其“ hidden”属性设置为YES。 Both of these settings make the UIView invisible. 这两个设置使UIView不可见。

I'd suggest using a modal view controller - unless there's some reason you want the other buttons to show. 我建议使用模式视图控制器-除非出于某些原因您希望其他按钮显示。 You would set a separate view controller for each modal view, rather than a transparent view. 您将为每个模式视图设置一个单独的视图控制器,而不是透明视图。 Then, use the view controller's 'presentModalViewController:animated:' method to control it. 然后,使用视图控制器的'presentModalViewController:animated:'方法进行控制。

Note that modal view controllers can be nested (one can call another), so you can have more than one chained together, as needed. 请注意,模态视图控制器可以嵌套(一个可以调用另一个),因此您可以根据需要将多个链接在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM