2
@Namespace var ns

    var body: some View {
        ZStack {
            Color(.black)
            TabView {
                ForEach(0..<5) { i in
                    Text("item \(i)")
                        .foregroundColor(.white)
                        .matchedGeometryEffect(id: i, in: ns)
                        .frame(maxWidth: .infinity)
                }
            }
                .tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))

        }
    }

When I tried to give each TabView item an effect id, it complains Multiple inserted views in matched geometry group Pair<Int, ID>(first: 0, second: SwiftUI.Namespace.ID(id: 180)) have isSource: true, results are undefined.

What's the correct way to assign a matchedGeometryEffect id to items in PageTabView so that I can zoom in and out with transition like the iOS photos app?

Or is it a bug of SwiftUI?

JackJack
  • 612
  • 2
  • 12
  • 28
  • From my experience, matchedGeometryEffect does not do anything in most cases I think it has some issues to acutely be useful. – ios coder Mar 12 '21 at 00:47
  • Looks like `PageTabViewStyle` specific bug. – Asperi Mar 12 '21 at 05:52
  • It's the TabView. You can create your own TabView easily. Check this answer: https://stackoverflow.com/questions/72496023/adding-animation-to-tabviews-in-swiftui-when-switching-between-tabs – MGY Dec 03 '22 at 05:56

0 Answers0