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

    Professional Community Investment Yields Big Returns

    March 13, 2026

    From transparency to action: What the latest Microsoft email security benchmark reveals

    March 13, 2026

    Launch of DevNet Content Search MCP Server

    March 13, 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 – Why does my page scroll up when I tap on a button?
    iOS Development

    ios – Why does my page scroll up when I tap on a button?

    big tee tech hubBy big tee tech hubJanuary 25, 2026013 Mins Read
    Share Facebook Twitter Pinterest Copy Link LinkedIn Tumblr Email Telegram WhatsApp
    Follow Us
    Google News Flipboard
    ios – Why does my page scroll up when I tap on a button?
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link


    I have a fairly simple view.

    It’s a trip itinerary with two parts:

    1. A horizontally scrolling list of dates at the top of the page.

    2. A vertically scrolling list of days (each day contains many trip stops).

    I’ve added logic for .scrollPosition() so that as the user scrolls the vertical list, the horizontal list can update which day the user is currently active on the page.

    Similarly, when a user taps on a day in the horizontal list at the top of the page, I have it set up to automatically scroll down to that day in the vertical list.

    Here is that code:

    struct TripView: View {
        @Environment(\.dismiss) private var dismiss
        
        @Binding var trip: Trip
    
        @State private var activeDate: String?
    
        var body: some View {
            VStack(spacing: 0) {
                // HORIZONTAL DATE PICKER
                ScrollViewReader { proxy in
                    ScrollView(.horizontal, showsIndicators: false) {
                        LazyHStack(spacing: 16) {
                            ForEach(trip.days, id: \.id) { day in
                                Button(action: {
                                    withAnimation(.spring(duration: 0.3)) {
                                        activeDate = day.date
                                    }
                                }, label: {
                                    VStack(spacing: 2) {
                                        Text(day.date.formatDate(fromFormat: "yyyy-MM-dd", toFormat: "d") ?? "")
                                            .background(activeDate == day.date ? Color.blue : Color.clear)
                                    }
                                })
                                .id(day.date)
                            }
                        }
                    }
                    .onChange(of: activeDate) { oldValue, newValue in
                        print("Active date changed to: \(newValue)")
                        
                        if let newValue {
                            withAnimation {
                                proxy.scrollTo(newValue, anchor: .center)
                            }
                        }
                    }
                }
    
                // VERTICAL CONTENT LIST
                ScrollView {
                    LazyVStack(spacing: 0) {
                        ForEach($trip.days) { $day in
                            TripDayView(
                                tripId: trip.id,
                                day: $day
                            )
                            .id(day.date)
                        }
                    }
                    .scrollTargetLayout()
                }
                .scrollPosition(id: $activeDate, anchor: .top)
            }
        }
    }
    

    The problem I’m facing is inside TripDayView below.

    struct TripDayView: View {
        @EnvironmentObject var tripManager: TripManager
    
        let tripId: Int
        @Binding var day: Day
        
        @State private var showingActionSheet: Bool = false
        
        var body: some View {
            Section {
                headerView
                
                ListStopsView(tripId: tripId, stops: $day.stops)
            }
        }
    
        var headerView: some View {
            VStack(alignment: .leading, spacing: 0) {
                HStack(spacing: 0) {
                    VStack(alignment: .leading, spacing: 0) {
                        Text(day.date.formatDate(fromFormat: "yyyy-MM-dd", toFormat: "EE, MMM d") ?? "")
                    }
                    
                    Spacer()
                    
                    Button(action: {
                        showingActionSheet = true
                    }, label: {
                        Image("Ellipsis Vertical")
                    })
                    .confirmationDialog("", isPresented: $showingActionSheet, titleVisibility: .hidden) {
                        Button("Option 1") {
                            //
                        }
                        
                        Button("Option 2") {
                            //
                        }
                        
                        Button("Option 3") {
                            //
                        }
                    }
                }
            }
        }
    }
    

    When I tap on the Button (that sets showingActionSheet = true), the vertical list in TripView scrolls up when the confirmationDialog is shown.

    What is causing this? How can I fix it?

    It seems to be related to .scrollPosition() because when I comment out that line, it doesn’t scroll up when I tap the button. But I need to keep that functionality.



    Source link

    button iOS page scroll tap
    Follow on Google News Follow on Flipboard
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    tonirufai
    big tee tech hub
    • Website

    Related Posts

    ios – SwiftUI toolbar symbol change without popping

    March 13, 2026

    ios – SwiftUI iOS26+ Transition or Animation after TextField value entered

    March 12, 2026

    uikit – Why the title doesn’t follow the navigation inline state in iOS 26

    March 11, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

    Professional Community Investment Yields Big Returns

    March 13, 2026

    From transparency to action: What the latest Microsoft email security benchmark reveals

    March 13, 2026

    Launch of DevNet Content Search MCP Server

    March 13, 2026

    The Easiest Way to Test Batteries

    March 13, 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!

    Professional Community Investment Yields Big Returns

    March 13, 2026

    From transparency to action: What the latest Microsoft email security benchmark reveals

    March 13, 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.