是否有可能暗淡UIView,但允许背后的元素触摸?
你怎么会在顶部有一个灰色的覆盖,但允许触摸它下面的button?
您可以将overlay的userInteraction
设置为false
。
如上所述,您可以将userInteractionEnabled
设置为NO
。
但要注意:当你创build一个全屏透明视图,并将其userInteractionEnabled
设置为NO
, 该视图的所有子视图将不会响应用户操作 。 如果你在视图上添加一个button,它将不会响应用户点击! 还有另外一个问题:如果你设置该视图的alpha
值是透明的,例如0.4
,那么它的所有子视图也将是透明的!
解决方法很简单:不要在透明视图中放置任何子视图,而是将其他元素添加为视图的同胞。 这里是Objective-C代码来展示我的意思:(注意说明这一切的意见):
//Create a full screen transparent view: UIView *vw = [[UIView alloc] initWithFrame:self.view.bounds]; vw.backgroundColor = [UIColor greenColor]; vw.alpha = 0.4; vw.userInteractionEnabled = NO; //Create a button to appear on top of the transparent view: UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 80, 44)]; btn.backgroundColor = [UIColor redColor]; [btn setTitle:@"Test" forState:UIControlStateNormal]; [btn setTitle:@"Pressed" forState:UIControlStateHighlighted]; //(*) Bad idea: [vw addSubview:btn]; //(**) Correct way to have the button respond to user interaction: // Add it as a sibling of the full screen view [self.view addSubview:vw]; [self.view addSubview:btn];
- 为什么WKWebView不显示video? – 斯威夫特3
- iOS8 Beta Ad-Hoc App下载(itms-services)
- 故事板和笔尖兼容?
- 使用NSURLSession清除networking故障后的临时下载文件
- 未加载库:@ rpath / Alamofire.framework / Alamofire
- 在UITableView中显示和隐藏特定的单元格types(可能带有animation)
- 实例消息的接收者types是前向声明popToRootViewController
- 应用程序被杀后,使用NSURLSessionUploadTask恢复上传任务?
- Swift如何获得UIAlertController标题的高度