I am following the Spring 2023 Stanford iOS programming class. In the Memorize game, we add a FlyingNumber as an overlay above a card which resulted in a score change and animate the number up or down depending on positive or negative score change. The instructor sets zIndex to 1 or 0 depending on whether that card caused the score change. The intent is to ensure that the FlyingNumber is above all the other cards being displayed. This works in iOS 17.0, but in iOS 17.2, if the FlyingNumber is negative it slides under the cards below it in the grid. The behavior in iOS 17.2 is as if the .zIndex modifier is not present.
private var cards: some View {
AspectVGrid(game.cards, aspectRatio: Constants.aspectRatio) { card in
if isDealt(card) {
CardView(card, gradient: game.gradient)
.matchedGeometryEffect(id: card.id, in: dealingNamespace)
.transition(.asymmetric(insertion: .identity, removal: .identity))
.padding(4)
.overlay(FlyingNumber(number: scoreChange(causedBy: card)))
.zIndex(scoreChange(causedBy: card) != 0 ? 1 : 0)
.onTapGesture {
choose(card)
}
}
}
}