Hey I have an issue can anyone help me. I’m trying to slide my cards when I press draw but it don’t work. Im not sure. I tried the toggle button but that’s not what I need. Any advice
I love this site in particular, but do you mean like this:
https://swiftontap.com/pagetabviewstyle
Please note you can hide the dots with .never.
Something like that but when I press draw I just want it to slide to the next random integer I select so it’ll be a different card @ekraus0227
try doing
if cardDealt.random()
or somewhere in deal()
What goes inside?
Any are you talking about the way you doing it or my way?
Can you provide code so that I can send you what I mean please? It’s just easier that way.
@ekraus0227
struct GameView: View {
@Environment(.dismiss) private var dismiss
@State var cardDealt = " "
@State var dealtCard = false
@State private var currentIndex = 0
var body: some View {
ZStack {
Image("white-background")
.resizable()
.ignoresSafeArea()
VStack {
HStack {
Spacer()
if dealtCard {
Image(cardDealt)
.resizable()
.cornerRadius(15)
.aspectRatio(contentMode: .fill)
.transition(.slide)
}
Spacer()
}.shadow(radius: 4)
Spacer()
HStack {
Button {
//Action for button
withAnimation(.easeIn) {
deal()
}
} label:{
// How the button look
Text("Draw")
.foregroundColor(.white)
.padding()
.background(.black)
.cornerRadius(15.0)
.font(.system(size:25))
.fontWeight(.bold)
}
Button {
//Action for button
dismiss()
} label:{
// How the button look
Text("End Game")
.foregroundColor(.white)
.padding()
.background(.black)
.cornerRadius(15.0)
.font(.system(size:25))
.fontWeight(.bold)
}
}.buttonBorderShape(.capsule)
}
}
}
func deal() {
let cpuCardValue = Int.random(in:1...20)
cardDealt = "card" + String(cpuCardValue)
dealtCard = true
}
}
struct GameView_Previews: PreviewProvider {
static var previews: some View {
GameView()
}
}
Just trying to make it slide to the left like a slideshow showing one card at a time when I press Draw
Ok so you want the slider to go left when you hit draw, then have a random card appear. Alright.
And I see you have
let cpuCardValue = Int.random(in:1…20)
Which should be randomizing the card. So you’re just having the issue of the animation part then?
Yes that’s correct
Eh I’m not a senior developer by any means. Though I don’t think that page tab style is what you want. Cause then people could go back on the cards… not sure if you can block that. Think not though. So you’d need just an animation. Something I haven’t spent much time on.
ok thanks
https://www.youtube.com/results?search_query=swiftui+animation+examples+
honestly I’d check out what YouTube has to offer for this to find out different ways of animating. Using your resources are important, and I mean, maybe you’d like to do a spinning motion of the image and it come up with a new image. There’s plenty of options out there. See what you like!
Yea thanks I think I can figure this using a for loop but we shall see
Ok I got it to where when I run the simulator the first card slides but the rest use some kind of animation but they don’t slide. @ekraus0227 do you know why I used the same code basically
The same code? The problem with page tabview style is that people can swipe back on the cards. Obviously an unwanted action. I don’t know what the code looks like right now.
The code that I posted when I run on the simulator and press draw the first card slides the others do not.