简体   繁体   English

禁用透明视图上的交互,而不会影响其子视图和按钮

[英]Disable interaction on transparent view without affecting its subviews and buttons

I want to make a floating menu in a view that will be later added to many tab view view controllers. 我想在视图中制作一个浮动菜单,稍后将其添加到许多选项卡视图视图控制器中。 So I want the view itself to be transparent and doesn't receive interactions while keeping users able to interact with the menu buttons. 因此,我希望视图本身是透明的,并且在保持用户能够与菜单按钮交互的同时不进行交互。

As in the picture below: 如下图所示:

在此处输入图片说明

I tried to set the view alpha to 0, it cascaded down to all its subviews. 我试图将视图alpha设置为0,它级联到其所有子视图。

Tried to set userInteractionEnabled to NO it did cascade down to all subviews as well. 试图将userInteractionEnabled设置为NO,它也确实向下层叠了所有子视图。

Any suggestions?? 有什么建议么??

Create a custom view and override the pointInside: , it returns false when the point isn't within an eligible child view. 创建一个自定义视图override pointInside:如果该点不在合格的子视图内,则返回false

It could look like this: 它可能看起来像这样:

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
    for subview in subviews {
        if !subview.hidden, subview.userInteractionEnabled, subview.frame.contains(point) {
            return true
        }
    }
    return false
}

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

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