如何让我的视图上的滑动手势透明?

时间:2017-05-24 18:18:03

标签: ios uigesturerecognizer

我正在制作滑动手势识别器,特别是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")
}

1 个答案:

答案 0 :(得分:0)

将视图的背景颜色设置为ClearColor而不是alpha设置为0。

swipeView.backgroundColor = UIColor.clearColor()