简体   繁体   English

iOS - 仅使子视图可单击

[英]iOS - Make only subview clickable

I am trying to make a custom dialog view. 我正在尝试创建自定义对话框视图。 I have come pretty far, however there is one issue. 我已经走了很远,但有一个问题。 When my dialog has popped up, I can press on textfields behind it. 当我的对话框弹出时,我可以按下它后面的文本字段。 How can I make sure that the user can only click on the subview that is the dialog view when it is present? 如何确保用户只能单击作为对话框视图的子视图?

Simple solution: when you show dialog create view 简单解决方案:当您显示对话框创建视图时

 CGRect viewBackFrame =  (CGRect){
        .origin = CGPointZero,
        .size = parentView.frame.size
    };
 UIView* viewBack = [[UIView alloc] initWithFrame:viewBackFrame];
 viewBack.backgroundColor = [UIColor clearColor];
 [parent insertSubview:viewBack belowSubview:dialog];

UIView has a property called exclusiveTouch that is supposed to do what you are trying to achieve. UIView有一个名为exclusiveTouch的属性,它应该做你想要实现的目标。 Setting your dialog's exclusiveTouch property to YES should do the trick. 将对话框的exclusiveTouch属性设置为YES应该可以解决问题。

Link to apple docs 链接到苹果文档

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

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