Post

Replies

Boosts

Views

Activity

Attach magnetically an object in SwiftUI
Hello guys! 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. Here's. my code: 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()) If anyone knows how to do this, please help me. Thanks
2
0
379
Mar ’22
Build a website
Hello developers! I have a question about which programming language is good for building a website. I searched on the internet and it says that CSS and HTML are the most used, so suppose I want to use CSS, now the question is: where can I code to build the website? For example if I want to code in SwiftUI there are some apps (Xcode and Swift Playgrounds) to do it, but how can I do with the website in CSS? And what is the WebKit, can I still use it to build web pages using SwiftUI? If someone has the right answer, please help me. Thanks.
2
0
3k
Aug ’22
Error appeared
Hi friends! I was developing an app, everything was working OK, but when I played the app on my iPhone connecting it via cable to the Mac an error has appeared and it says "The operation couldn't be completed. Unable to log in with account ... " "No profiles for ... were found: Xcode couldn't find any iOS app Development provisioning devices matching ..." and I'm not able to try it on my iPhone. Any suggestion or idea to fix these errors?
2
0
1.3k
Dec ’22
Different position for different elements
Hello guys! In SwiftUI is there a function to show different objects in random order or can I just do this by assigning the coordinates to each individual element? For example, suppose I have a lot of circles, and I want to position them randomly, how can I do it? Thanks in advance.
2
0
710
Apr ’23
Need a help
Hi there, I'm studying SwiftUI on my own, but unfortunately I'm still not able to write complex lines of code, or even code an app independently, which is very frustrating for me. I love coding, it's a way to express my creativity. I already have a lot of ideas, but I can't put them into practice because I feel like I don't have learned enough about this programming language. Can any of you suggest me some free courses or other resources that have also helped you in your first steps with coding?
2
0
1k
Jul ’23
Unexpected behaviour SwiftUI
Hello there, I want to create letters "rain" effect in SwiftUI, actually in this code, I would like letters to start from the top and once they reach the end of the screen, be randomly placed again all over the X axis at the top of the screen (red part in the picture) and fall linear, but unfortunately these letters make strange movements, and I don't understand why they react this way I tried to change the offset values, but it didn't work at all! :( import SwiftUI struct ContentView: View { let screenWidth = UIScreen.main.bounds.width let screenHeight = UIScreen.main.bounds.height let letters: [String] = ["A", "B", "C", "D"] @State private var yOffset: CGFloat = 0.0 var body: some View { VStack { ForEach(letters, id: \.self) { letter in Text(letter) .padding() .font(.largeTitle) .position(x: CGFloat.random(in: 0...screenWidth)) .offset(x: 0, y: yOffset) .animation(Animation.linear(duration: 5.0).repeatForever(autoreverses: false)) .onAppear { yOffset = screenHeight - 90 } } Spacer() } } } Please, If anyone knows how to fix this issue, help me.
2
0
524
Feb ’24
Can I draw other shaper in Xcode?
Hello world, can I draw something else in Xcode, like when I write Circle(), it draws me a circle in the screen, or when I write Rectangle(), it appear a rectangle in the simulator... So are there other commands to draw some different shapes like this or I can elusively use these ones? Thank you.
1
0
484
Dec ’21
Flip animation in SwiftUI
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())
1
0
3.0k
Jan ’22
Add Text to an animated object
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())
1
0
566
Jan ’22
Move according to the button
Hello there! I would like to move the object according to the button press. In this code, I have the circle and I like to move it down if I press the down button. Can anyone tell me how can I do this? Thanks. import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View {         Circle()             .frame(width: 80, height: 80)         Spacer(minLength: 20)             Button{             } label: {                 Image(systemName: "arrowtriangle.down.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }     } } PlaygroundPage.current.setLiveView(ContentView())
1
0
1.2k
Feb ’22
What's wrong here?
Hello everyone, I'm trying to make particle effect in SwiftUI, following a YouTube tutorial and this is what I made, despite I wrote the same code as the video, it gives me this error (which doesn't appear in the video). So can anyone tell me what I did wrong? Here's my code: And the link for the tutorial: https://www.youtube.com/watch?v=oj4HEqkDvBY import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View {         Text("Hello, world!")     } } struct ParticleEffect: ViewModifier {     let count: Int     let duration: Double = 2.0     @State var time: Double = 0.0     func body(content: Content) -> some View {         let animation = Animation.linear(duration: duration)             .repeatForever(autoreverses: false)         return  ZStack {             ForEach(0..<count) { index in                 content                     .scaleEffect(CGFloat((duration-self.time)/duration))                     .modifier(ParticleMotion(time: self.time)) // ERROR: Cannot find 'ParticleMotion' in scope                     .opacity((duration-self.time)/duration)                     .animation(animation.delay(Double.random(in: 0..<self.duration)))                     .blendMode(.plusLighter)             }             .onAppear {                 withAnimation() {                     self.time = duration                 }             }         }     } } PlaygroundPage.current.setLiveView(ContentView())
1
0
477
Mar ’22