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

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

    January 25, 2026

    Konni hackers target blockchain engineers with AI-built malware

    January 24, 2026

    The Human Behind the Door – O’Reilly

    January 24, 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, 2026003 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

    swift – iOS suspends app after BLE discovery even though I start Always-authorized location udpates

    January 24, 2026

    ios – ASAuthorizationControllerDelegate always returns .canceled for Face ID passcode fallback and failed attempts

    January 23, 2026

    ios – SwiftUI view state resetting after alert is shown

    January 22, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Editors Picks

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

    January 25, 2026

    Konni hackers target blockchain engineers with AI-built malware

    January 24, 2026

    The Human Behind the Door – O’Reilly

    January 24, 2026

    Nanomaterials Transformed by Engineering Shape, Not Chemistry

    January 24, 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!

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

    January 25, 2026

    Konni hackers target blockchain engineers with AI-built malware

    January 24, 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.