HomeiOS Developmentios - How one can transfer photos between scrollviews

ios – How one can transfer photos between scrollviews


I’m creating an app for iOS utilizing swiftui, however please let me know if there are any unclear factors. I wish to drag a picture displayed in a single scrollview and transfer it to a different scrollview.My present downside is that after I drag the picture to maneuver it, as soon as the picture is out of the scrollview it does not present up and I can not transfer it to a different scrollview.I’d recognize it for those who may inform me easy methods to clear up this downside

thanks.

import SwiftUI

struct ContentView: View {
    @State personal var pageOffsets: [CGSize] = Array(repeating: .zero, depend: 50)
    @State personal var pageGridColumns: [Int] = Array(repeating: 0, depend: 50)
    let grids = Array(repeating: GridItem(.fastened(80)), depend: 4)
    
    var physique: some View {
        LazyVStack {
            ScrollView() {
                LazyHStack {
                    LazyVGrid(columns: grids) {
                        ForEach((1...50), id: .self) { num in
                            Web page(str: String(num))
                                .cornerRadius(8)
                                .body(peak: 60)
                                .offset(pageOffsets[num - 1])
                                .gesture(
                                    DragGesture()
                                        .onChanged { worth in
                                            pageOffsets[num - 1] = worth.translation
                                        }
                                        .onEnded { worth in
                                            let columnIndex = Int(spherical(worth.translation.width / 80))
                                            let newOffset = CGSize(width: CGFloat(columnIndex) * 80, peak: 0)
                                            withAnimation {
                                                pageOffsets[num - 1] = newOffset
                                                pageGridColumns[num - 1] = columnIndex
                                            }
                                        }
                                )
                                .onAppear {
                                    pageGridColumns[num - 1] = (num - 1) % 4
                                }
                        }
                    }
                }
            }
            ScrollView() {
                LazyHStack {
                    LazyVGrid(columns: grids) {
                        ForEach((1...50), id: .self) { num in
                            Web page(str: String(num))
                                .cornerRadius(8)
                                .body(peak: 60)
                                .offset(pageOffsets[num - 1])
                                .gesture(
                                    DragGesture()
                                        .onChanged { worth in
                                            pageOffsets[num - 1] = worth.translation
                                        }
                                        .onEnded { worth in
                                            let columnIndex = Int(spherical(worth.translation.width / 80))
                                            let newOffset = CGSize(width: CGFloat(columnIndex) * 80, peak: 0)
                                            withAnimation {
                                                pageOffsets[num - 1] = newOffset
                                                pageGridColumns[num - 1] = columnIndex
                                            }
                                        }
                                )
                                .onAppear {
                                    pageGridColumns[num - 1] = (num - 1) % 4
                                }
                        }
                    }
                }
            }
        }
    }
}

struct Web page: View {
    let colours: [Color] = [.green, .blue, .pink, .orange, .purple]
    let str: String

    var physique: some View {
        ZStack {
            colours.randomElement()
            Textual content(str)
                .font(.title)
                .foregroundColor(.white)
        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments