I want to use RotationGesture and MagnificationGesture simultaneously. However I also use these gestures individually. Here is my code.
struct TmpView10: View {
@State private var magnify: CGFloat = 1
@State private var lastMagnify: CGFloat = 1
@State private var angle: Angle = .degrees(.zero)
@State private var lastAngle: Angle = .degrees(.zero)
var body: some View {
VStack () {
ZStack () {
Image("someImage")
.resizable()
.aspectRatio(contentMode: .fit)
.scaleEffect(self.magnify)
.rotationEffect(self.angle)
.gesture(RotationGesture()
.onChanged{ angle in
self.angle = angle + self.lastAngle
}
.onEnded { angle in
self.lastAngle = self.angle
}
)
.simultaneousGesture(MagnificationGesture(minimumScaleDelta: 0.5)
.onChanged{ v in
let delta = v / self.lastMagnify
self.lastMagnify = v
self.magnify *= delta
}
.onEnded{ v in
self.lastMagnify = 1
}
)
.clipShape(Circle())
.overlay(
Circle().stroke(LinearGradient(gradient: Gradient(colors: [.yellow, .red, .purple]), startPoint: .bottomLeading, endPoint: .topTrailing), lineWidth: 5))
}
}
}
}
By this code I can use two gestures simultaneously. But once I only rotate Image, MagnificationGesture stops working. Are there any way to use both simultaneousGesture and individual gesture ?