滑动选项swiftUI滚动视图

问题描述

请原谅我在快速搜索之前是否曾问过这个问题,找不到答案。我正在创建一个应用程序,用户可以在其中接收朋友的请求,并且希望用户能够向左滑动以显示接受或拒绝请求的不同选项

为了更清楚,这就是我想要的样子

enter image description here

enter image description here

如果有帮助,这是我的滚动视图

 ScrollView(.vertical){
                        vstack(spacing: 40){
                            
                            // Todo Add Chat Rooms
                            ForEach(ChatRooms,content: {room in
                                //Create an in app link that navigates to messaging screen
                                NavigationLink(
                                    destination: MessageDetail(messageShowing: $detailShowing),isActive: $detailShowing,label: {
                                        //Create a chat room card
                                        Button(action: {
                                            detailShowing = true
                                        },label: {
                                            ChatRoomView(room: room)
                                        }).buttonStyle(PlainButtonStyle())
                                        
                                    }
                                    
                                ).buttonStyle(PlainButtonStyle())
                            
                        })
                        
                    }.padding(.top,30)
                }

edit:我尝试将水平滚动视图嵌套在垂直滚动视图中,如下所示 ScrollView(.horizo​​ntal){ vstack(间距:40){

                                // Todo Add Chat Rooms
                                ForEach(ChatRooms,content: {room in
                                    //Create an in app link that navigates to messaging screen
                                    ScrollView (.horizontal) {
                                        NavigationLink(
                                            destination: MessageDetail(messageShowing: $detailShowing),label: {
                                                //Create a chat room card
                                                Button(action: {
                                                    detailShowing = true
                                                },label: {
                                                    ChatRoomView(room: room)
                                                }).buttonStyle(PlainButtonStyle())

                                            }

                                        ).buttonStyle(PlainButtonStyle())
                                    }



                                })

                           }.padding(.top,30)
                        }

但这就是我的结局

enter image description here

解决方法

try this class :-

https://github.com/EnesKaraosman/SwipeCell

how to use:-

Simply add onSwipe(leading,trailing) method to your list item
    List {
        HStack {
            Text("Enes Karaosman")
            Spacer()
        }
        .listRowInsets(EdgeInsets())
        .onSwipe(leading: [
          .. // here add slots
        ])
        
    }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...