UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How to make a .onAppear

Forums > SwiftUI

Hello together,

i am working on a Set Game and I want the cards to swing on the view via the .transition(.asymmetric(insertion: .offset(x: 100.0, y: 100.0), removal: .offset(x: 100.0, y: 100.0))) command.

Actually, they leave the screen by doing exactly the offset, but they just appear at the start on the program.

Can someone tell me what I am doing wrong?

    @ViewBuilder
    private func body (for size: CGSize) -> some View{
        let paddingAllSidesInCards:CGFloat = 8
        if card.isFaceUp || !card.isMatched
        {
            GeometryReader { geo in
                VStack(alignment: .center) {
                    Group
                    {

                            ForEach( 0..<card.numberofsymbols)
                            { numberofcards in

                                let cardshape = cardViewModelShape.getShape(Card: card, size: size, numberOfCards: card.numberofsymbols)
                                    cardshape
                                    .aspectRatio(1,contentMode: .fit)
                                    .frame(minWidth: 20, idealWidth: 100, maxWidth: .infinity, minHeight: 20, idealHeight: 100, maxHeight: .infinity, alignment: .center)
                                    .scaleEffect(card.isSelected ? 1.2 : 1)
                                    .animation(.spring(response: (card.isSelected ? 1:0), dampingFraction: 0.1, blendDuration: .infinity))
                            }.padding(paddingAllSidesInCards)
                        //Implicit animation - with linear execution
                    }
                }
                .cardify(isFaceUp: card.isFaceUp)
//                .animation(Animation.easeIn(duration: 2))

            }
            .transition(.asymmetric(insertion: .offset(x: 100.0, y: 100.0), removal: .offset(x: 100.0, y: 100.0)))

        }
    }
}

2      

Hi together, I have added the question to Stackoverflow as well with an additional video and a few comments: https://stackoverflow.com/questions/65635111/swiftui-transition-asymmetric-not-working-with-offset/65635552?noredirect=1#comment116057892_65635552

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.