Skip to content

Instantly share code, notes, and snippets.

@bmnick
Created November 25, 2014 19:45
Show Gist options
  • Select an option

  • Save bmnick/dd7f570753ed32852576 to your computer and use it in GitHub Desktop.

Select an option

Save bmnick/dd7f570753ed32852576 to your computer and use it in GitHub Desktop.
import UIKit
/**
A specialized scroll view that allows clicking through a trailing section of it's content. This is used for a
transparent section at the end of the target rows that can be tapped through. It simply reports any points
within the last `clickThroughOffset` points of the view as not belonging to the view.
*/
private class BNOffsetClickThroughScrollView: UIScrollView {
/**
The number of points at the right side of the scroll view that do not belong to the view.
*/
var clickThroughOffset: CGFloat = 44.0
/**
This is used by the framework to determine if a point is within the given view. In our override, we report
points in the last `clickThroughOffset` of the view as not being inside the scroll view.
*/
override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
let hitPosition = contentOffset.x + point.x
if super.pointInside(point, withEvent: event) && hitPosition < maxTappableX() {
return true
} else {
return false
}
}
/**
Returns the maximum location that is within the view.
*/
func maxTappableX() -> CGFloat {
return contentSize.width - clickThroughOffset
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment