可能会在scrollview上添加视图,并添加滑动手势,如下所示:
var swipeGesture = UISwipeGestureRecognizer()
let directions: [UISwipeGestureRecognizer.Direction] = [.up, .down]
for direction in directions {
swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(swipeView(_:)))
view.addGestureRecognizer(swipeGesture)
swipeGesture.direction = direction
view.isUserInteractionEnabled = true
view.isMultipleTouchEnabled = true
}
self.view = view
scrollView.delegate = self
@objc func swipeView(_ sender : UISwipeGestureRecognizer){
if sender.direction == .up {
scrollView.setContentOffset(CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.height), animated: true)
} else if sender.direction == .down {
scrollView.setContentOffset(CGPoint(x: 0, y: 0), animated: true)
}
}