Close Menu
  • Home
  • AI
  • Big Data
  • Cloud Computing
  • iOS Development
  • IoT
  • IT/ Cybersecurity
  • Tech
    • Nanotechnology
    • Green Technology
    • Apple
    • Software Development
    • Software Engineering

Subscribe to Updates

Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

    What's Hot

    Xcode 26.3 adds agentic coding support

    February 5, 2026

    B.C. housing standards need to keep pace with EV uptake, warns new roadmap

    February 5, 2026

    From guardrails to governance: A CEO’s guide for securing agentic systems

    February 5, 2026
    Facebook X (Twitter) Instagram
    Facebook X (Twitter) Instagram
    Big Tee Tech Hub
    • Home
    • AI
    • Big Data
    • Cloud Computing
    • iOS Development
    • IoT
    • IT/ Cybersecurity
    • Tech
      • Nanotechnology
      • Green Technology
      • Apple
      • Software Development
      • Software Engineering
    Big Tee Tech Hub
    Home»iOS Development»ios – ScrollView Behviour in swiftUI
    iOS Development

    ios – ScrollView Behviour in swiftUI

    big tee tech hubBy big tee tech hubNovember 12, 2025002 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    ios – ScrollView Behviour in swiftUI
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    Want B over A in Zstack, Offset of scroll needs to be 200 (height of A). Either B is pinned to top and has 200 offset or B starts at 200 y position and as we scroll up its y also changes, so after 200 point up move it covers A completely. Whatever part of A is visible needs to be interactive, no matter however we approach this. B should scroll over A.

    I have reached the below version but don’t trust it too much and neither it is very fluid.

    // MARK: - B over A with dynamic offset; A interactive while visible
    struct CollapsingOverlayScrollExample: View {
        private let headerHeight: CGFloat = 200
        @State private var scrolledUp: CGFloat = 0
        @State private var baselineTop: CGFloat? = nil
        @State private var displayedScrolledUp: CGFloat = 0
    
        var body: some View {
            ZStack(alignment: .top) {
                // View A (Header) behind
                VStack {
                    Text("👆 Tap Header (A)")
                        .font(.headline)
                        .foregroundColor(.white)
                    Text("Visible part remains interactive")
                        .foregroundColor(.white)
                }
                .frame(height: headerHeight)
                .frame(maxWidth: .infinity)
                .background(Color.blue)
                .onTapGesture {
                    print("👉 Header (A) tapped!")
                }
                .zIndex(0)
    
                // View B (ScrollView) on top, offset down by remaining visible header
                ScrollView {
                    VStack(spacing: 20) {
                        // Sentinel to track scroll offset within the ScrollView
                        GeometryReader { geo in
                            Color.clear
                                .preference(key: ScrollOffsetKey.self,
                                            value: geo.frame(in: .named("ROOT")).minY)
                        }
                        .frame(height: 0)
    
                        ForEach(1...30, id: \.self) { i in
                            Text("Scroll Item \(i)")
                                .frame(maxWidth: .infinity)
                                .frame(height: 60)
                                .background(Color.orange.opacity(0.9))
                                .cornerRadius(8)
                                .padding(.horizontal)
                        }
                    }
                    .padding(.top, 16)
                }
                .background(Color.green.opacity(0.5))
                // While header is visible, keep B's frame below it so A remains tappable
                .offset(y: max(0, headerHeight - displayedScrolledUp))
                .zIndex(1)
            }
            .coordinateSpace(name: "ROOT")
            .onPreferenceChange(ScrollOffsetKey.self) { topInRoot in
                // Calibrate baseline once to avoid initial jump due to layout timing.
                if baselineTop == nil {
                    baselineTop = topInRoot
                }
                let base = baselineTop ?? headerHeight
                // Positive distance scrolled upwards relative to the baseline.
                let delta = base - topInRoot
                scrolledUp = max(0, delta)
            }
            .onChange(of: scrolledUp) { newValue in
                withAnimation(.interactiveSpring(response: 0.25, dampingFraction: 0.86, blendDuration: 0.2)) {
                    displayedScrolledUp = newValue
                }
            }
            .edgesIgnoringSafeArea(.all)
        }
    }
    



    Source link

    Behviour iOS ScrollView SwiftUI
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    An Introduction to Liquid Glass for iOS 26

    February 5, 2026

    c# – MAUI black screen on iOS when “Linker behaviour” set to “SDKs Only”

    February 4, 2026

    ios – ZStack background ignoring safe area while content respects it, all scrolling together in ScrollView

    February 3, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Xcode 26.3 adds agentic coding support

    February 5, 2026

    B.C. housing standards need to keep pace with EV uptake, warns new roadmap

    February 5, 2026

    From guardrails to governance: A CEO’s guide for securing agentic systems

    February 5, 2026

    An Introduction to Liquid Glass for iOS 26

    February 5, 2026
    About Us
    About Us

    Welcome To big tee tech hub. Big tee tech hub is a Professional seo tools Platform. Here we will provide you only interesting content, which you will like very much. We’re dedicated to providing you the best of seo tools, with a focus on dependability and tools. We’re working to turn our passion for seo tools into a booming online website. We hope you enjoy our seo tools as much as we enjoy offering them to you.

    Don't Miss!

    Xcode 26.3 adds agentic coding support

    February 5, 2026

    B.C. housing standards need to keep pace with EV uptake, warns new roadmap

    February 5, 2026

    Subscribe to Updates

    Get the latest technology news from Bigteetechhub about IT, Cybersecurity and Big Data.

      • About Us
      • Contact Us
      • Disclaimer
      • Privacy Policy
      • Terms and Conditions
      © 2026 bigteetechhub.All Right Reserved

      Type above and press Enter to search. Press Esc to cancel.