8.7 C
Canberra
Tuesday, October 28, 2025

ios – The way to permit a UIScrollView within a UIHostingController to go contact occasions to a view beneath it with out breaking scrolling?


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.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles