如何在透明的情况下在我的视图上接收滑动手势?

How can I receive swipe gesture on my view while having it transparent?

我正在制作一个滑动手势识别器,它特别接收滑动 UIView 但我也希望它是透明的,使 alpha=0 不响应滑动。

这是添加手势的代码:

@IBOutlet weak var swipeView: UIView!
let swipeRec = UISwipeGestureRecognizer()

 override func viewDidLoad() {
    super.viewDidLoad()
    swipeRec.addTarget(self, action: #selector(ViewController.swipedView))
    swipeView.addGestureRecognizer(swipeRec)
    swipeView.isUserInteractionEnabled = true
    swipeRec.direction=UISwipeGestureRecognizerDirection.right
}

func swipedView(){
    print("swiped")
}

将视图的背景色设置为 ClearColor 而不是 alpha 为 0 应该可行。

swipeView.backgroundColor = UIColor.clearColor()