Sunday, September 25, 2022
HomeiOS Developmentios - How do I add swipe again gesture in swift?

ios – How do I add swipe again gesture in swift?


I discovered a query like this on Stack Overflow nevertheless it didn’t appear to work. Perhaps I am implementing it mistaken, or it not works. I’ve a @Binding showDetailView that when equals true, exhibits the element view.

This element view has a customized again button that works. I would like to have the ability to do a swipe gesture that performs the identical perform because the again button.

The code I discovered that appears prefer it might assistance is:

extension UINavigationController: UIGestureRecognizerDelegate {
    override open func viewDidLoad() {
        tremendous.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = self
    }

    public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return viewControllers.depend > 1
    }
}

The code for my essential view (product web page) is:

struct ProductPage: View {
   
    
    @StateObject var MarketplaceModel = MarketplaceViewModel()
    @State non-public var selectedMarketplaceFilter: MarketplaceFilterViewModel = .productList
    @Namespace var animation : Namespace.ID
    @State var showDetailProduct = false
    @State var selectedProduct : Product!
    
    var physique: some View {
        

        var columns = Array(repeating: GridItem(.versatile()), depend: 2)
        
        ZStack{
            
            VStack(spacing: 10){
                
                
                if MarketplaceModel.merchandise.isEmpty{
                    
                    Spacer()
                    
                    ProgressView()
                    
                    Spacer()
                }
                else{
                    
                    ScrollView(.vertical, showsIndicators: false, content material: {
                        

                        LazyVGrid(columns: Array(repeating: GridItem(.versatile(),spacing: 10), depend: 2),spacing: 20){
                            
                            ForEach(MarketplaceModel.filteredProduct){product in
                                
                                    ProductView(productData: product)
                                        .onTapGesture {
                                            withAnimation {
                                                
                                                selectedProduct = product
                                                showDetailProduct.toggle()

                                            }
                                        }
                            }
                        }
                    })
                }
            }
            
           
            if selectedProduct != nil && showDetailProduct{

                ProductDetailView(showDetailProduct: $showDetailProduct, productData: selectedProduct, product_id)
                    .transition(.transfer(edge: .trailing))
            }
       }
    }
}

The code for my element view (product element view) is:

struct ProductDetailView: View {
    

    @StateObject var MarketplaceModel = MarketplaceViewModel()
    @Binding var showDetailProduct: Bool
    @Namespace var animation: Namespace.ID
    @EnvironmentObject var marketplaceData: MarketplaceViewModel
    var productData : Product
    var product_id: String
    

    var physique: some View {
        
        NavigationView{
        
        VStack{
            
            VStack{
                
                // Title Bar...
                HStack {
                    
                    Button(motion: {
                                            withAnimation{showDetailProduct.toggle()}

                                        }) {
                                            Picture(systemName: "arrow.backward.circle.fill")
                                            

                    Spacer()
                   
                    ForEach(MarketplaceModel.product_details_array){ objects in

                        Textual content(objects.product_name)
                            .font(.largeTitle)
                            .fontWeight(.heavy)
                            .foregroundColor(.black)
                    }
                }
            }
                
      ScrollView {


                VStack {
     
                    Textual content(productData.product_name)
                  
                    Textual content(productData.product_details)
                    
                }
            }
        
            
            
                }
            }
        }
    }
}

How would I’m going about including the again swipe gesture? (Operating Xcode 13.4.1)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments