简体   繁体   English

显示子视图时如何在SuperView上禁用UserInteraction?

[英]How to Disable UserInteraction on SuperView when Subview is displayed?

I have created a Custom UIView , added it as subview to ViewController and displayed it as PopUp. 我创建了一个Custom UIView ,将其作为子视图添加到ViewController并将其显示为PopUp。 Now, what i want is that when UIView is displayed, the SuperView. 现在,我想要的是当显示UIView显示的是SuperView。

ie my viewController should Disable user interaction. 即我的viewController应该禁用用户交互。

I have tried below code but it disables whole view including PopUp.So how can i disable UserInteraction. 我试过下面的代码,但它禁用了包括PopUp.So的整个视图,所以我该如何禁用UserInteraction。

userInteractionEnabled = NO;

Please give me some idea. 请给我一些想法。

Thank you. 谢谢。

You could also add the view as a subview to the application window and use a transparent background, such as: 您还可以将视图作为子视图添加到应用程序窗口中,并使用透明背景,例如:

CGSize popupSize = CGSizeMake(200, 200);
UIWindow *win = [[[UIApplication sharedApplication] delegate] window];
CGRect rect = CGRectMake(win.bounds.size.width/2-popupSize.width/2, win.bounds.size.height/2-popupSize.height/2, popupSize.width, popupSize.height);
UIView *myCustomView = [[MyCustomView alloc] initWithFrame:rect];
[win addSubView:myCustomView];
self.view.userInteractionEnabled = NO;

I haven't tested this code, but I've added stuff to window before. 我尚未测试此代码,但之前已在窗口中添加了内容。 To remove the view, just write: 要删除视图,只需编写:

[myCustomView removeFromSuperView];

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

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