简体   繁体   中英

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. Setting your dialog's exclusiveTouch property to YES should do the trick.

Link to apple docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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