Hello guys,
everything was working perfectly but I can't do a thing please help me.
I was trying to put into this Rectangle some text , I've tried several lines of code but I can't put the Text INTO the rectangle. Can someone help me?
Here's the code
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var flipped = false
var body: some View {
Group {
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(self.flipped ? .red : .orange)
.padding()
.rotation3DEffect(self.flipped ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
self.flipped.toggle()
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello everyone,
I would like to a flip animation, so that when I press on the rectangle it will flip to other side (like in a cards game)
How can I do that?
Thank you
Here's my code:
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
Group {
Button {
} label: {
Rectangle()
.frame(width: 140, height: 170)
.foregroundColor(Color(.systemTeal))
.cornerRadius(20)
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
Hi guys
I'm trying to build a game (cards game precisely) and I need that when the user finds the same cards the game has to stop... I watched different videos on internet and tried a lot of lines of code but I can't do this. So please, can anyone help me?
Thank you.
I leave you my code:
import SwiftUI
import PlaygroundSupport
let columns = [GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible())]
struct ContentView: View {
@State var flipped1 = false
@State var flipped2 = false
@State var flipped3 = false
@State var flipped5 = false
@State var flipped6 = false
@State var flipped7 = false
@State var flipped8 = false
@State var flipped9 = false
var body: some View {
LazyVGrid(columns: columns) {
Group {
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(flipped1 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("😀").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped1 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped1 ? 1 : 0))
.rotation3DEffect(flipped1 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default, value: flipped1)
.onTapGesture {
flipped1.toggle()
}
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(flipped2 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("😜").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped2 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped2 ? 1 : 0))
.rotation3DEffect(flipped2 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
flipped2.toggle()
}
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(self.flipped3 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("😘").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped3 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped3 ? 1 : 0))
.rotation3DEffect(self.flipped3 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
self.flipped3.toggle()
}
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(self.flipped5 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("🥶").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped5 ? 180 : 0), axis: (x: CGFloat(0), y:CGFloat(10), z: CGFloat(0))).opacity(flipped5 ? 1 : 0))
.rotation3DEffect(self.flipped5 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
self.flipped5.toggle()
}
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(self.flipped6 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("😡").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped6 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped6 ? 1 : 0))
.rotation3DEffect(self.flipped6 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
self.flipped6.toggle()
}
Group {
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(self.flipped7 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("🥶").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped7 ? 180 : 0), axis: (x: CGFloat(0), y:CGFloat(10), z: CGFloat(0))).opacity(flipped7 ? 1 : 0))
.rotation3DEffect(self.flipped7 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
self.flipped7.toggle()
}
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(self.flipped8 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("😘").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped8 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped8 ? 1 : 0))
.rotation3DEffect(self.flipped8 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
self.flipped8.toggle()
}
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(self.flipped9 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("😡").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped9 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped9 ? 1 : 0))
.rotation3DEffect(self.flipped9 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
self.flipped9.toggle()
}
}
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
Hi guys,
I need a little help with my code,
I was creating this playground and I want that the cards will stay face up if they are equal... I can't find tutorial and I tried different lines of code but it doesn't work. So please can anyone help me there? I'll thank you very much.
struct ContentView: View {
@State var flipped1 = false
@State var flipped2 = false
var body: some View {
LazyVGrid(columns: columns) {
Group {
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(flipped1 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("😀").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped1 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped1 ? 1 : 0))
.rotation3DEffect(flipped1 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default, value: flipped1)
.onTapGesture {
flipped1.toggle()
}
RoundedRectangle(cornerRadius: 20)
.frame(width: 140, height: 170)
.foregroundColor(flipped2 ? Color(.systemIndigo) : .purple)
.padding()
.overlay(Text("😀").font(.system(size: 80)).rotation3DEffect(Angle(degrees: flipped2 ? 180 : 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0))).opacity(flipped2 ? 1 : 0))
.rotation3DEffect(flipped2 ? Angle(degrees: 180): Angle(degrees: 0), axis: (x: CGFloat(0), y: CGFloat(10), z: CGFloat(0)))
.animation(.default)
.onTapGesture {
flipped2.toggle()
}
Hello there,
What is the difference between @ObservedObject, ObservableObject and @StateObject in SwiftUI?
Hello! I was trying to create a cards game following the Stanford University CS193p tutorial and I had a problem, in the tutorial they didn't add any animation and I would like to add one but I can't understand where exactly I have to write the command. Can someone help me?
Thank you very much!
My code:
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View{
HStack {
CardView()
CardView()
CardView()
CardView()
}
.padding()
.foregroundColor(Color(.systemRed))
}
}
struct CardView: View {
@State var isFaceUp = false
var body: some View {
ZStack {
let shape = RoundedRectangle(cornerRadius: 20)
if isFaceUp {
shape.fill().foregroundColor(.white)
shape.stroke(lineWidth: 3)
Text("😀").font(.system(size: 80))
} else {
shape.fill()
}
}
.onTapGesture(perform: {
isFaceUp = !isFaceUp
})
}
}
PlaygroundPage.current.setLiveView(ContentView())
Hello everyone,
I was trying to create something in Swift Playgrounds when this error appears, can someone tell me what it means and how can I fix it?
Thanks
Hey there,
I would like to create a card game (I'm following the Stanford University's tutorial) and I want to Scroll the view according to the position of the mouse, like if it's to the top so I would like that it automatically rolls up, so if it's to the down, scroll automatically to the down:
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View{
HStack {
CardView()
CardView()
CardView()
CardView()
}
.padding()
.foregroundColor(Color(.systemRed))
}
}
struct CardView: View {
@State var isFaceUp = false
var body: some View {
ZStack {
let shape = RoundedRectangle(cornerRadius: 20)
if isFaceUp {
shape.fill().foregroundColor(.white)
shape.stroke(lineWidth: 3)
Text("😀").font(.system(size: 80))
} else {
shape.fill()
}
}
.onTapGesture(perform: {
isFaceUp = !isFaceUp
})
}
}
PlaygroundPage.current.setLiveView(ContentView())
Hey there, I would like to create a card game (I'm following the Stanford University's tutorial) and I want to Scroll the view according to the position of the mouse, like if it's to the top so I would like that it automatically rolls up, so if it's to the down, scroll automatically to the down:
This is my code:
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View{
HStack {
CardView()
CardView()
CardView()
CardView()
}
.padding()
.foregroundColor(Color(.systemRed))
}
}
struct CardView: View {
@State var isFaceUp = false
var body: some View {
ZStack {
let shape = RoundedRectangle(cornerRadius: 20)
if isFaceUp {
shape.fill().foregroundColor(.white)
shape.stroke(lineWidth: 3)
Text("😀").font(.system(size: 80))
} else {
shape.fill()
}
}
.onTapGesture(perform: {
isFaceUp = !isFaceUp
})
}
}
PlaygroundPage.current.setLiveView(ContentView())
Hi there!
I'm trying to create an app which scrolls automatically when my mouse goes to the top of the screen or to the bottom. For example the mouse goes towards the top, it has to scroll to the top and vice versa. So if it possible help me please.
Thanks very much!
I leave you my code:
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View{
HStack {
CardView()
CardView()
CardView()
CardView()
}
.padding()
.foregroundColor(Color(.systemRed))
}
}
struct CardView: View {
@State var isFaceUp = false
var body: some View {
ZStack {
let shape = RoundedRectangle(cornerRadius: 20)
if isFaceUp {
shape.fill().foregroundColor(.white)
shape.stroke(lineWidth: 3)
Text("😀").font(.system(size: 80))
} else {
shape.fill()
}
}
.onTapGesture(perform: {
isFaceUp = !isFaceUp
})
}
}
PlaygroundPage.current.setLiveView(ContentView())
Hello everyone!
I have updated my iPhone to iOS 15.2.1 and before this update my phone after the good the sleep mode turns off, it appears a screen with written on it “Good Morning” and the weather. But since I have updated my device to iOS 15.2.1 it isn’t showing me this screen. Is it a feature that Apple has deleted or is this a bug?
Thank you.
Helle everyone!
I was preparing for this year's Swift Student Challenge, and I have some questions about it. I know that Apple every year changes something in the Challenge, but I want to be ready. As I know for participating to the challenge I have to build a playground in Swift Playgrounds. So for that in Swift Playgrounds I have to use SwiftUI kit or build it in another way?
PS: if someone knows some Swift Playgrounds tutorials please suggest me here.
Thank you very much!
Hi everyone, can anyone tell me how can I create images for Xcode assets. Because now I want to create my own image not using the readymade.
Thank you!
Hello there!
I would like to build a playground using Swift Playgrounds in AR. And I want to ask if it is possible to do it on the Mac or I can only do it with the iPad?
Thank you.
Hello,
I've seen that Apple has posted a news for some online sessions starting from February 15 to March 29. And I'd like to participate there but for now I haven't posted any app on the App Store. So I would like to ask that I can still participate also if I'm in the beginning?
These are the sessions: https://developer.apple.com/events/view/upcoming-events
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
App Store
App Store Connect
Mac App Store