Declare state var for rectangle width and height.
Use this var in the .frame()
Change the values when you swipe.
Here is a code example:
struct BlueRectangleView: View {
@State var height: CGFloat = 100
@State var width: CGFloat = 200 // If you also want to change width
var body: some View {
VStack {
Rectangle()
.fill(Color.blue)
.frame(width: width, height: height)
.cornerRadius(10)
.shadow(radius: 5)
.padding()
.gesture(
DragGesture(minimumDistance: 5)
.onChanged { value in
let newHeight = height + value.translation.height / 20 // /20: To slow down change
let newWidth = width + value.translation.width / 20 // /20: To slow down change
if newHeight > 5 && newHeight < 500 {
height = newHeight
print("New height\(height)")
}
if newWidth > 5 && newWidth < 400 {
width = newWidth
print("New width\(width)")
}
}
)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.white)
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: