继承一个scrollview,重写下面方法
方法一、
func panBack(gestureRecognizer:UIGestureRecognizer)->Bool {
let location_X:CGFloat = 100;
if gestureRecognizer == panGestureRecognizer {
let pan = gestureRecognizer as! UIPanGestureRecognizer
let point = pan.translation(in: self)
let state = gestureRecognizer.state
if state == UIGestureRecognizerState.began || state == UIGestureRecognizerState.possible {
let location = gestureRecognizer.location(in: self)
if point.x > 0 && location.x < location_X && contentOffset.x <= 0 {
return true
}
}
}
return false
}
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if panBack(gestureRecognizer: gestureRecognizer) {
return false
}
return true
}
方法二、
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
var hitView = super.hitTest(point, with: event)
if point.x <= 20 {
hitView = nil
}else {
hitView = super.hitTest(point, with: event)
}
return hitView
}