Wednesday, September 10, 2025
HomeiOS Developmentios - SwiftUI shrink view on dragging edges

ios – SwiftUI shrink view on dragging edges


I’m attempting to implement a video trimmer UI in SwiftUI as follows:

 struct SimpleTrimmer: View {
    @State non-public var startPosition: CGFloat = 0
    @GestureState non-public var isDragging: Bool = false
    
    @State non-public var lastStartPosition: CGFloat = .zero
    @State non-public var frameWidth:CGFloat = 300
    
    var physique: some View {
        HStack(spacing: 10) {
                Picture(systemName: "chevron.compact.left")
                    .body(top:70)
                    .body(width:20)
                    .padding(.horizontal, 5)
                    .background(Colour.blue)
                    .offset(x: startPosition)
                    .gesture(
                        DragGesture(minimumDistance: 0)
                            .updating($isDragging, physique: { worth, out, transaction in
                                out = true
                                
                            })
                            .onChanged { worth in
                                let translation = worth.translation.width
                                startPosition = translation + lastStartPosition
                            }.onEnded { _ in
                                lastStartPosition = startPosition
                                NSLog("Final begin place (lastStartPosition)")
                            }
                    )
            
                
                Spacer()
                
                Picture(systemName: "chevron.compact.proper")
                .body(top:70)
                .body(width:20)
                .padding(.horizontal, 5)
                .background(Colour.blue)
            }
            .foregroundColor(.black)
            .font(.title3.weight(.semibold))
            .padding(.horizontal, 7)
            .padding(.vertical, 3)
            .background(.yellow)
            .clipShape(RoundedRectangle(cornerRadius: 7))
            .body(width: frameWidth)
          //  .offset(x: startPosition)
            .onGeometryChange(for: CGFloat.self) { proxy in
                proxy.measurement.width
            } motion: { width in
                print("width = (width)")
            }
    }
}

enter image description here

This works for shifting the left hand of the trimmer when dragged. What I would like can be to shrink the SimpleTrimmer view because the ends are dragged. It merely does not work it doesn’t matter what I do (similar to adjusting the offset and width of the principle HStack, and so forth).

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments