struct House: View {
var physique: some View {
ZStack {
SomeSwiftUIView()
UIHostingControlleredScrollView()
}
}
}
class CollaborativeScrollView: UIScrollView, UIGestureRecognizerDelegate {
var lastContentOffset: CGPoint = .zero
var initialContentOffset: CGPoint = .zero
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return otherGestureRecognizer.view is CollaborativeScrollView
}
override func hitTest(_ level: CGPoint, with occasion: UIEvent?) -> UIView? {
guard let hitView = tremendous.hitTest(level, with: occasion) else { return nil }
// If the hit view will not be the foundation view controller's view, return it
// guard hitView == rootViewController?.view else { return hitView }
// Examine if there are any seen, interactive subviews on the contact level
let interactiveSubview = hitView.subviews.first { subview in
!subview.isHidden &&
subview.alpha > 0.01 &&
subview.isUserInteractionEnabled &&
subview.body.comprises(level)
}
// If there's an interactive subview, return the hit view (permit interplay)
// In any other case, return nil (go by means of)
return interactiveSubview != nil ? hitView : nil
}
}
In my present implementation, I’m able to override hit check and go a single contact simply superb by means of the ScrollView. Nonetheless, this prevents scrolling from occurring totally on the ScrollView after I start dragging on a clear space. I would like to have the ability to drag on a clear space to scroll. However I additionally want to have the ability to faucet by means of the clear space to faucet a button that’s beneath the ScrollView.
