You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI List滚动异常:仅导航箭头边缘可滚动,求解决方案

SwiftUI List滚动异常:仅NavigationLink箭头区域可触发滚动

在SwiftUI的List组件中,我使用NavigationLink包裹列表项实现点击跳转详情页的功能,但出现了滚动异常:只有点击屏幕边缘的NavigationLink箭头区域时才能触发List滚动,其他区域无法滚动。

我尝试过多种方法都没能解决问题,虽然知道可以用ScrollView搭配ForEach实现滚动,但因为需要使用.onDelete() modifier实现左滑删除列表项的功能,所以更倾向于继续使用List组件。

MyRecipesView代码(省略@State变量和数据库获取逻辑)

List{
    ForEach(customRecipesList){ customRecipe in
        LazyVStack{
            NavigationLink {
                CustomRecipeDetailView(customRecipe: customRecipe)
            } label: {
                CustomRecipeCardView(customRecipe: customRecipe)
                    .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
                    .listRowSeparator(.hidden, edges: .all)
                    .listRowBackground(Color(white: 1.0))
                    .padding(.vertical, 10)
                    .gesture(
                        LongPressGesture(minimumDuration: 0.7)
                            .updating($press, body: { currentState, gestureState, transaction in
                                gestureState = currentState
                            })
                            .onEnded({ value in
                                editCustomRecipe = customRecipe
                            })
                    )//gesture
            }//NavigationLink Label
        }//LazyVStack
    }
}

RecipeCardView代码

struct RecipeCardView: View {
    
    var recipe:Recipe?
    
    var body: some View {
        VStack{
            
            AsyncImage(url: URL(string: recipe?.image ?? "")) { image in
                image
                    .resizable()
                    .scaledToFit()
                    .cornerRadius(12)
            } placeholder: {
                Image("norecipe")
                    .resizable()
                    .scaledToFit()
                
            }
            
            VStack(alignment:.leading, spacing: 12){
                
                Text(recipe?.title ?? "Strawberry Ice Cream")
                    .font(.title.weight(.bold))
                    .foregroundColor(.green)
                    .lineLimit(1)
                
                HStack(spacing:30){
                    VStack{
                        HStack{
                            Image(systemName: "heart.fill")
                                .foregroundColor(.red)
                            Text("Likes")
                        }
                        Text("\(recipe?.aggregateLikes ?? 4)")
                    }//Rating
                    
                    VStack{
                        HStack{
                            Image(systemName: "person.2.fill")
                                .foregroundColor(.blue)
                            Text("Serves")
                        }
                        
                        Text("\(recipe?.servings ?? 2)")
                    }
                    
                    VStack{
                        HStack{
                            Image(systemName: "clock.fill")
                                .foregroundColor(.brown)
                            Text("Prep")
                        }
                        
                        Text("\(recipe?.readyInMinutes ?? 45) minutes")
                    }
                    
                }//Main HStack
                
            }//Recipe data Vstack
            .padding()
            
        }//VStack
        .background(.white)
        .cornerRadius(12)
        .shadow(color: .gray.opacity(0.5), radius: 8, x: 0, y: 5)
    }//body
}

更新:问题根源在于长按手势,移除该手势并自定义SwipeAction后,滚动恢复正常。


内容的提问来源于stack exchange,提问作者Amey079

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 11:41:05