SwiftUI|SwiftUI - 旋转手势RotationGesture基本使用

1.带有圆角的矩形形状

struct RotationGesturesView: View { var body: some View { RoundedRectangle(cornerRadius: 25.0, style: .continuous) .fill(Color.blue) .frame(width: 200, height: 200, alignment: .center) .padding() .background(Color.red) } }

  1. 实现RotationGesture
struct RotationGesturesView: View { //放大手势 @GestureState var magniValue:CGFloat = 1 var magnificationGestures:some Gesture { MagnificationGesture() //current 当前值 //state 实时值 //动画 .updating($magniValue) { (current, state, trans) in state = current } }var body: some View { RoundedRectangle(cornerRadius: 25.0, style: .continuous) .fill(Color.blue) .frame(width: 200, height: 200, alignment: .center) .padding() .background(Color.red) } }

GestureState 用于手势系列的属性包装器,用法类似State。
【SwiftUI|SwiftUI - 旋转手势RotationGesture基本使用】3.调用放大手势
struct RotationGesturesView: View { //放大手势 @GestureState var magniValue:CGFloat = 1 var magniGestures:some Gesture { MagnificationGesture(minimumScaleDelta: 1) //current 当前值 //state 实时值 //动画 .updating($magnification) { (current, state, trans) in state = current } }var body: some View { RoundedRectangle(cornerRadius: 25.0, style: .continuous) .fill(Color.blue) .frame(width: 200, height: 200, alignment: .center) .padding() .background(Color.red).scaleEffect(magniValue) .gesture(magniGestures) } }

    推荐阅读