无法在ScrollView上识别UISwipeGesture

时间:2019-10-26 15:55:09

标签: ios swift scrollview uigesturerecognizer

在我的应用中,有一个scrollView(pageScrollView),它是一个类似界面(https://www.youtube.com/watch?v=1_daE3IL_1s)的

但是,当我尝试使用以下代码在滚动视图上获取手势时,它无法检测到,有人可以帮我吗?

let leftSwipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(leftSwipedByUser(_:)))
leftSwipeGesture.direction = .left
self.pageScrollView.addGestureRecognizer(leftSwipeGesture)


let rightSwipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(rightSwipedByUser(_:)))
rightSwipeGesture.direction = .right
self.pageScrollView.addGestureRecognizer(rightSwipeGesture)

操作如下:

@objc func leftSwipedByUser(_ gesture:UISwipeGestureRecognizer) {
    print("left swipe")
}
@objc func rightSwipedByUser(_ gesture:UISwipeGestureRecognizer) {
    print("right swipe")
}

0 个答案:

没有答案