History
Loading...
Loading...
October 1, 2025
.rotationEffect() combined with @GestureState for smooth rotation gestures. The @GestureState property wrapper automatically resets to its initial value when the gesture ends, making it perfect for temporary transformations.This approach separates persistent rotation state from temporary gesture state, while allowing multiple gestures to work together seamlessly. The `@State` property maintains the accumulated rotation, while `@GestureState` handles the live gesture feedback.
@State private var currentRotation: Angle = .zero
@GestureState private var gestureRotation: Angle = .zero
@GestureState private var magnification: CGFloat = 1.0
var body: some View {
RoundedRectangle(cornerRadius: 12)
.fill(.blue.gradient)
.frame(width: 150, height: 150)
.rotationEffect(currentRotation + gestureRotation)
.scaleEffect(magnification)
.simultaneousGesture(
RotationGesture()
.updating($gestureRotation) { value, state, _ in
state = value
}
.onEnded { value in
currentRotation += value
}
)
.simultaneousGesture(
MagnificationGesture()
.updating($magnification) { value, state, _ in
state = value
}
)
}Using `simultaneousGesture()` instead of chaining gestures prevents gesture conflicts and creates more intuitive user interactions. The separation of concerns between permanent and temporary state makes the code more predictable and easier to debug, while providing smooth visual feedback during multi-touch interactions.