美文网首页
SwiftUI 按钮动画

SwiftUI 按钮动画

作者: movingshop | 来源:发表于2021-03-11 10:25 被阅读0次

struct ContentView: View {
    //list 使用方法
    @State private var animationAmount: CGFloat = 1
    @State var enabled:Bool = false
    
    var body: some View {
        ZStack{
        Button("Tap Me") {
                self.enabled = true
                
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
                    animationAmount = 0.9
                    self.enabled = false
                }
            }
        
            .frame(width: 100, height: 100)
            .background(Color.blue )
            .foregroundColor(.white)
            .clipShape(Circle())
            .scaleEffect(enabled ? 0.9 : 1.0)
            .animation(.interpolatingSpring(stiffness: 300, damping: 10))
            .background(
                ZStack{
                    if !enabled {
                        Circle()
                        .stroke(Color.blue)
                        .scaleEffect(animationAmount)
                            .opacity(Double(1.5 - animationAmount))
                        .onAppear{
                            animationAmount = 1.5
                        }
                        .animation(.default)

                    }
                }

            )
        }
    }
    
    
}

相关文章

网友评论

      本文标题:SwiftUI 按钮动画

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