swiftui:嵌套在scrollview中

发布于 2025-02-06 21:48:36 字数 1737 浏览 2 评论 0原文

我已经尝试了所有我能想到的一切,但是当嵌套在卷轴内时,我无法将此按钮始终如一地发射。如果我将ScrollView更改为列表,它可以正常工作,但是我不希望手表上的列表的UI,我更喜欢使用scrollview。我认为这与系统检测到按钮上的滚动和水龙头的水龙头有关,但不确定如何修复或任何解决方法?

struct WatchWorkoutSummaryView: View {
    
    @EnvironmentObject var workoutManager:  WorkoutManager
    
    
    var body: some View {
        ScrollView {
            EffortLevelRingViewForWatch(workoutState: WatchWorkoutState.After)
            Divider()
                .padding(.horizontal)
            IntensityViewForWatch()
            Divider()
                .padding(.horizontal)
            HeartRateZonesViewForWatch(workoutState: WatchWorkoutState.After)
            Divider()
                .padding(.horizontal)
            AerobicAnaerobicWatchMasterView()
            Divider()
                .padding(.horizontal)
            VStack {
                SummaryView().environmentObject(workoutManager)
                Button(action: {
                    print("button is tapped")
                    workoutManager.dismissLiveWorkoutTabViewSheet()
                    workoutManager.resetWorkoutManager()
                }, label: {
                    Text("Done")
                        .foregroundColor(.white)
                    
                })
                    .background(
                        
                        Color.buttonColor
                            .cornerRadius(10)
                            
                    )
                   
                    .buttonStyle(BorderedButtonStyle(tint: .clear))
                    .padding(.horizontal)
                    .animation(nil)
            }
            .padding(.vertical)
        }
        //This doesn't work.
        .animation(nil) 
    }
}

I've tried everything I can think of but I can't get this button to fire consistently when nested inside a ScrollView. If I change the ScrollView to a List, it works fine, but I don't want the UI of a list on the Watch, I would prefer to use a ScrollView. I think it's related to the system detecting taps to scroll and taps on the button but not sure how to fix or any workarounds?

struct WatchWorkoutSummaryView: View {
    
    @EnvironmentObject var workoutManager:  WorkoutManager
    
    
    var body: some View {
        ScrollView {
            EffortLevelRingViewForWatch(workoutState: WatchWorkoutState.After)
            Divider()
                .padding(.horizontal)
            IntensityViewForWatch()
            Divider()
                .padding(.horizontal)
            HeartRateZonesViewForWatch(workoutState: WatchWorkoutState.After)
            Divider()
                .padding(.horizontal)
            AerobicAnaerobicWatchMasterView()
            Divider()
                .padding(.horizontal)
            VStack {
                SummaryView().environmentObject(workoutManager)
                Button(action: {
                    print("button is tapped")
                    workoutManager.dismissLiveWorkoutTabViewSheet()
                    workoutManager.resetWorkoutManager()
                }, label: {
                    Text("Done")
                        .foregroundColor(.white)
                    
                })
                    .background(
                        
                        Color.buttonColor
                            .cornerRadius(10)
                            
                    )
                   
                    .buttonStyle(BorderedButtonStyle(tint: .clear))
                    .padding(.horizontal)
                    .animation(nil)
            }
            .padding(.vertical)
        }
        //This doesn't work.
        .animation(nil) 
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文