防止快速点击视图 [英] Prevent click through view in swift

查看:14
本文介绍了防止快速点击视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 和 swift 中工作,我创建了一个视图作为一个菜单,可以在点击时切换,当菜单出现时,我仍然可以单击它下面的测试按钮.我不希望这种情况发生.我希望视图后面的所有内容都被禁用,优先考虑菜单视图.(查看下图)

I'm working in Xcode and swift, I created a view acting as a menu that toggles on tap, when the menu comes out I can still click a test button underneath it. I don't want that to happen. I want everything behind the view to be disabled giving priority to the menu view. (View Image below)

示例应用的屏幕截图

  • 请记住,我不考虑使用一个按钮,如果是这样,我会禁用该特定按钮.此页面将是滚动视图,并且是动态的.

这是我正在使用的代码:

this is the code that I'm using:

@IBAction func MenuButton(sender: UIButton) {
    if self.MenuView.frame.origin.x == -180 {
        UIView.animateWithDuration(0.5, animations:{
            self.MenuView.frame = CGRectMake(self.MenuView.frame.origin.x + 180, self.MenuView.frame.origin.y, self.MenuView.frame.size.width, self.MenuView.frame.size.height)
        })

    } else {
        UIView.animateWithDuration(0.5, animations:{
            self.MenuView.frame = CGRectMake(self.MenuView.frame.origin.x - 180, self.MenuView.frame.origin.y, self.MenuView.frame.size.width, self.MenuView.frame.size.height)
        })
    }
}

视图在左侧隐藏 180 像素,当单击菜单按钮时,视图将向右移动 180 像素,从而将其带到前面.该函数检查视图是否已经打开,以便它可以将其动画返回 180 像素以隐藏它.

the view is hidden 180 pixels on the left side, when the menu button is clicked the view will animate 180 pixels to the right which brings it to the front. The function checks if the view is already opened so it can animate it back 180 pixel to hide it.

我唯一需要的是禁止点击视图.

The only thing I need is to disable clicking through the view.

推荐答案

按钮仍然可见和可点击的事实意味着它必须在菜单的前面.如果您重新排列事物的顺序,使菜单位于按钮的前面,那么您应该得到您正在寻找的结果.

The fact that the button is still visible and clickable means that it must be in front of the menu. If you rearrange the order of things so that the menu is in front of the button, then you should get the result that you are looking for.

这篇关于防止快速点击视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆