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)
}
}
- 实现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)
}
}
推荐阅读
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- 演讲手势
- SwiftUI|SwiftUI iOS 瀑布流组件之仿CollectionView不规则图文混合(教程含源码)
- Flutter|Flutter SwiftUI React 对比
- 旋转image、imageView
- 锦囊26(手势动画打造微信页眉的GIF动图)
- SwiftUI|SwiftUI 动画组件之Lottie小型高质量交互式的开源动画文件格式
- macOS|macOS SwiftUI 组件之 实用下拉菜单 (教程含源码)
- SwiftUI|SwiftUI iOS 组件之双值区间取值选择器RangeSlider支持颜色(教程含源码)
- Qt实战|Qt+OpenCV联合开发(二十一)--图像翻转与旋转