Post

Replies

Boosts

Views

Activity

How to change position of a shape
Hello guys! I would like to change the position of a shape but I can't understand which command I have to put in the code so that the square will be to the right. let columns: [GridItem] = [GridItem(.flexible()),                            GridItem(.flexible()),                            GridItem(.flexible())] struct ContentView: View {     var body: some View {         GeometryReader { geometry in             VStack{                 Spacer()                 ZStack {                     LazyVGrid(columns: columns) {                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                         Circle()                             .frame(width: 100, height: 100)                             .foregroundColor(Color(.systemBlue))                             .opacity(0.5)                             Rectangle()                                 .frame(width: 200, height: 80)                                 .foregroundColor(Color(.systemBlue))                                 .opacity(0.5)                                 .cornerRadius(60)                     }                 }                 Spacer()             }         }              } } Of course if I did something wrong, please tell me... Thank u, have a great day!
0
0
386
Dec ’21
Apple Developer Membership is activated
Hi, I heard that Apple will send me an email saying that my Apple developer membership is activated, with the confirmation and I can start exporting and publishing apps, but to me came 3 emails: welcome to the Apple Developer Program App Store connect good news! Your receipt for order — is ready But there isn’t any confirmation email, so how can I know if I can start posting my apps to App Store?
0
0
385
Dec ’21
Result of 'Text' initializer is unused
Hello there, I'm trying to create a button with it initially written "hello", then when I click on the button I would like the 'hello' to become a number. I already defined the variable (var Number = 1) and then I called Text("(Number)"). But when I recall the variable, ‘hello’ must change to number 1. It gives me this warning "Result of 'Text' initializer is unused" near Text("(Number)") under the func tapped()... and the text doesn't change. Here's my code: var Number = 1 struct NewView: View {     var body: some View {         Button {             tapped()         } label: {             Text("hello")         }     } }               func tapped() {     Text("\(Number)") } struct NewView_Previews: PreviewProvider {     static var previews: some View {         NewView()     } }
0
0
412
Dec ’21
Scroll according to mouse position
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())
0
0
373
Jan ’22
Scroll according to mouse position
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())
0
0
394
Jan ’22
Scroll automatically
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())
0
0
755
Jan ’22
Move the circle according the arrow
Hello everyone, Can someone tell me how to move the circle in the same position of the arrow (like to go up if I press up, down if I press down... and so right if I press right) but it doesn't go right, I can't know why. Please can someone help me to figure out this? Here's the code: import SwiftUI import PlaygroundSupport struct ContentView: View {     @State var offset: CGFloat = 0     var body: some View {         Circle()             .frame(width: 80, height: 80)             .position(x: 140, y: 140 + offset)         Spacer(minLength: 20)         Button(             action: {                 offset += 20                          }, label: {                 Image(systemName: "arrowtriangle.down.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }         )         Button(             action: {                 offset += 20                      }, label: {                 Image(systemName: "arrowtriangle.right.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }         )     } } PlaygroundPage.current.setLiveView(ContentView()) Thanks in advance.
0
0
610
Feb ’22
Change image with click
Hi there! I want to change the current circle to a rectangle when I press the Right button. Is it possible if yes how can I it? Code: struct ContentView: View { @State var vOffset: CGFloat = 0 @State var hOffset: CGFloat = 0 var body: some View { Circle() .frame(width: 80, height: 80) .position(x: 140 + hOffset, y: 140 + vOffset) Spacer(minLength: 20) Button( action: { vOffset += 20 }, label: { Image(systemName: "arrowtriangle.down.circle.fill") .resizable() .foregroundColor(.blue) .frame(width: 70, height: 70) .padding() } ) Button( action: { hOffset += 20 }, label: { Image(systemName: "arrowtriangle.right.circle.fill") .resizable() .foregroundColor(.blue) .frame(width: 70, height: 70) .padding() } ) } } Thanks.
0
0
474
Feb ’22
Attach magnetically an object in SwiftUI
Hello everyone! Can I attach one object to another using a magnate animation in SwiftUI? For example In the code below I want the blue square to attach with the red one, when I drag it near it. import PlaygroundSupport import SwiftUI struct ContentView:  View {     @State private var isDragging = false     @State private var dragOffset: CGSize = .zero     @State var position: CGSize = .zero     @State private var hovered = false     var body: some View {         RoundedRectangle(cornerRadius: 20)             .foregroundColor(.red)             .frame(width: 100, height: 100)             .position(x: 400, y: 350)         RoundedRectangle(cornerRadius: 20)             .foregroundColor(.blue)             .frame(width: 100, height: 100)             .position(x: 400, y: 350)             .animation(.default, value: hovered)             .offset(x: dragOffset.width + position.width, y: dragOffset.height + position.height)             .gesture(                 DragGesture()                     .onChanged({ value in                         self.dragOffset = value.translation                     })                     .onEnded({ value in                         self.position.width += value.translation.width                         self.position.height += value.translation.height                         self.dragOffset = .zero                     })             )     } } PlaygroundPage.current.setLiveView(ContentView()) Thanks.
0
0
307
Mar ’22
Attach objects in SwiftUI
Hi there! I want to attach 2 objects in SwiftUI when they'll near. import SwiftUI struct ContentView: View {     @State private var dragOffset: CGSize = .zero     @State private var position: CGSize = .zero     var body: some View{         Circle()             .frame(width: 140, height: 140)             .foregroundColor(.green)             .position(x: 150, y: 90)             .offset(x: dragOffset.width + position.width, y: dragOffset.height)             .gesture(DragGesture()                         .onChanged({ (value) in                              self.dragOffset = value.translation                         })             )         Circle()             .frame(width: 140, height: 140)             .foregroundColor(.blue)             .position(x: 500, y: 210)         Circle()             .frame(width: 140, height: 140)             .foregroundColor(.orange)             .position(x: 90, y: 70)     } } In my code I want to stick the green circle with one of the other 2, when it is close to them. Can anyone help me figure out this? Thanks in advance.
0
0
403
Apr ’22