Skip to content

Instantly share code, notes, and snippets.

@raulriera
Created May 3, 2016 10:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save raulriera/43dfd76a72d4ecb07a67510fb3f5d3c9 to your computer and use it in GitHub Desktop.
Save raulriera/43dfd76a72d4ecb07a67510fb3f5d3c9 to your computer and use it in GitHub Desktop.
import UIKit
// This class allows the "presentedController" to receive touches
// https://pspdfkit.com/blog/2015/presentation-controllers/
class PSPDFTouchForwardingView: UIView {
var passthroughViews: [UIView] = []
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
guard let hitView = super.hitTest(point, withEvent: event) else { return nil }
guard hitView == self else { return hitView }
for passthroughView in passthroughViews {
let point = convertPoint(point, toView: passthroughView)
if let passthroughHitView = passthroughView.hitTest(point, withEvent: event) {
return passthroughHitView
}
}
return self
}
}
@EvgenyKarkan
Copy link

Thanks for that!
Swift syntax is a bit outdated though, here is the up-to-date 5 version as of October 2021.

class PSPDFTouchForwardingView: UIView {

    var passthroughViews: [UIView] = []

    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        guard let hitView = super.hitTest(point, with: event) else {
            return nil
        }
        guard hitView == self else {
            return hitView
        }

        for passthroughView in passthroughViews {
            let point = convert(point, to: passthroughView)

            if let passthroughHitView = passthroughView.hitTest(point, with: event) {
                return passthroughHitView
            }
        }

        return self
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment