如何在UIView变透明后检测手势?

Joe*_*ang 1 cocoa-touch uiview ios swift

我有UIView一些其他UI组件来检测长按手势.当长按开始时,我想通过将背景颜色更改为灰色&alpha = 0.1来提示用户.

长按结束后,UIView必须将其更换为完全透明.我把它的alpha设置为0,但问题是......

不能再检测到其他人.

mainView = UIView()
mainView.frame = ...
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action:Selector("longPressed:"))
mainView.addGestureRecognizer(longPressRecognizer)

func longPressed(sender: UILongPressGestureRecognizer) {
    let view = sender.view!

    if sender.state == .Began {
        view.backgroundColor = UIColor.grayColor()
        view.alpha = 0.1
    } else if (sender.state == .Ended || sender.state == .Cancelled || sender.state == .Failed) {
        view.backgroundColor = UIColor.whiteColor()
        view.alpha = 0
    }
}
Run Code Online (Sandbox Code Playgroud)

将此UIView更改回原始状态的正确方法是什么,以便在最初创建时可以检测到其他手势?

Dan*_*all 6

将UIView的alpha属性设置为0将使其停止接收触摸.相反,将其背景设置为UIColor.clearColor()您希望它不可见的时间.