Xcode 11 Beta 5 - Modal triggers only once

前端 未结 1 1715
孤独总比滥情好
孤独总比滥情好 2021-01-27 07:38

I just upgrade to Xcode 11 Beta 5 and update my SwiftUI project.

In previous version I wanted to use PresentationLink component to show up a modal. I h

相关标签:
1条回答
  • 2021-01-27 07:49

    This is the same issue as https://stackoverflow.com/a/57087399/3179416

    Just move your .sheet outside of your ForEach.

    import SwiftUI
    
    struct Testing : View {
    
        var listViewItems: [Int] = [1, 2, 3]
    
            @State var show = false
    
    
            var body: some View {
    
    
                VStack {
                    HStack {
                        VStack(alignment: .leading) {
                            Text("Project title").font(.largeTitle).fontWeight(.heavy)
                            Text("Project subtitle").foregroundColor(Color.gray)
                        }
                        Spacer()
                    }.padding(.top, 78).padding(.leading, 60)
    
                    ScrollView(.horizontal, showsIndicators: false) {
                        HStack(spacing: 30) {
                            ForEach(listViewItems, id: \.self) { item in
                                GeometryReader { geometry in
                                    Button(action: { self.show.toggle()}) {
                                        Text("Button")
                                            .rotation3DEffect(Angle(degrees: Double((geometry.frame(in: .global).minX - 30) / -30)), axis: (x: 0, y: 10, z: 0))
                                    }
                                }.frame(width: 246, height: 360)
                            }
                        }.padding(30)
                        Spacer()
                    }.frame(width: UIScreen.main.bounds.width, height: 480)
                    .sheet(isPresented: self.$show, content: { Text("Modal") })
                    Spacer()
                }
            }
    }
    

    0 讨论(0)
提交回复
热议问题