0
import SwiftUI

struct ReviewsPageView: View {
    @State private var showingSheet = false

    var body: some View {
        VStack{
                Button(action: {
                    withAnimation(){
                        self.showingSheet.toggle()
                    }
                    
                }, label: {
                    HStack{
                        Image(systemName: "star.fill")
                            .foregroundColor(.white)
                        Text("REVIEWS / RATINGS")
                            .foregroundColor(.white)
                            .font(.headline)
                            .fontWeight(.semibold)
                            .padding(.vertical)
                    }
                })
                .frame(width: 300, height: 50)
                .background(colors.mid)
                .cornerRadius(30)
                .padding(.top,20)
                .shadow(color: colors.text, radius: 2, x: 0, y: 2)
                
                
                if(showingSheet)
                {
                    Rectangle()
                        .fill(colors.mid)
                        .frame(width: 200, height: 200)
                        //.fill(colors.mid)
                        //.opacity(showingSheet ? 1.0 : 0.0)
                        .transition(.scale)
                }
                
            
        }
        
        
        
    }
}

struct ReviewsPageView_Previews: PreviewProvider {
    static var previews: some View {
        ReviewsPageView()
    }

这是我的动画过渡代码^^^

我想让框在单击按钮时展开,然后在再次单击时缩小。现在该框只是出现没有任何过渡,然后在第二次单击时过渡到较小的形状。

这是它的样子:

https://im7.ezgif.com/tmp/ezgif-7-01329e73f283.gif

4

0 回答 0