I tried out what I mentioned above to make sure it would work for our needs, and it does. Here are the implementation details:
Add a new PSPDFTouchForwardingView
class to your project.
import UIKit
// This class allows the "presentedController" to receive touches
// https://pspdfkit.com/blog/2015/presentation-controllers/
final class PSPDFTouchForwardingView: UIView {
final 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
}
}
Add a new touchForwardingView
var to the DraggablePresentationController
:
private lazy var touchForwardingView: PSPDFTouchForwardingView? = {
guard let containerView = containerView else { return nil }
return PSPDFTouchForwardingView(frame: containerView.bounds)
}()
Then change the presentationTransitionWillBegin
method to look like this where you add the touchForwardingView
at index 0 of the containerView
:
override func presentationTransitionWillBegin() {
guard let containerView = containerView else { return }
touchForwardingView!.passthroughViews = [presentingViewController.view]
containerView.insertSubview(touchForwardingView!, at: 0)
containerView.insertSubview(dimmingView, at: 1)
dimmingView.alpha = 0
dimmingView.backgroundColor = .black
dimmingView.frame = containerView.frame
}