【问题标题】:How can I receive swipe gesture on my view while having it transparent?如何在视图透明的同时接收滑动手势?
【发布时间】:2017-05-24 18:18:03
【问题描述】:

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

【问题讨论】:

    标签: ios uigesturerecognizer


    【解决方案1】:

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

    swipeView.backgroundColor = UIColor.clearColor()
    

    【讨论】:

      猜你喜欢
      • 2022-07-06
      • 2019-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-15
      相关资源
      最近更新 更多