美文网首页
SwiftUI - 旋转手势RotationGesture基本使

SwiftUI - 旋转手势RotationGesture基本使

作者: 妳的小粥果果 | 来源:发表于2020-12-30 16:51 被阅读0次

    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。

    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)
        }
    }
    

    相关文章

      网友评论

          本文标题:SwiftUI - 旋转手势RotationGesture基本使

          本文链接:https://www.haomeiwen.com/subject/qjvhoktx.html