Hello everyone!
Can someone tell me where to put animation when I use LazyVGrid, please?
Here’s my code:
struct MyEmoji : Hashable {
var char: String
var num: Int
}
struct ContentView39: View {
var emojis : [MyEmoji] = [MyEmoji(char: "🐶", num: 0), MyEmoji(char: "🐱", num: 1), MyEmoji(char: "🐱", num: 2), MyEmoji(char: "🦊", num: 3), MyEmoji(char: "🦁", num: 4), MyEmoji(char: "🐝", num: 5), MyEmoji(char: "🐼", num: 6), MyEmoji(char: "🐷", num: 7), MyEmoji(char: "🐮", num: 8)]
var body: some View {
LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) {
ForEach(emojis, id: \.self, content: { emoji in
emojiView(content: emoji.char)
})
}
}
Thanks in advance.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi there! I'm trying to build something in SwiftUI and I need a help on it. I want the orange circle to scale and expand, and fill the entire screen, whenI click on it.
Here's my code:
import SwiftUI
struct ContentView: View {
var body: some View {
Circle()
.frame(width: 120, height: 120)
.foregroundColor(.orange)
}
}
Thank you.
Hello everyone!
I'm having a problem with my code and I don't know how to fix it. In fact, when I click the green circle, it gets bigger by wiping out the others, but the purple overlaps. Is there a way to get the purple away too?
Another problem: I have a warning where it says .animation(.spring()) and the warning says "'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead."
import SwiftUI
struct ContentView: View {
var body: some View {
LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) {
createCircle()
.foregroundColor(.blue)
createCircle()
.foregroundColor(.green)
createCircle()
.foregroundColor(.purple)
createCircle()
.foregroundColor(.orange)
createCircle()
.foregroundColor(.yellow)
}
}
struct createCircle: View {
@State var scale : CGFloat = 0.25
var body: some View {
ZStack {
Circle()
.frame(width: 500 * scale, height: 500 * scale)
.onTapGesture {
scale = 5
}
.animation(.spring()) // WARNING: 'animation' was deprecated in iOS 15.0: Use withAnimation or animation(_:value:) instead.
.animation(.interpolatingSpring(stiffness: 50, damping: 1), value: scale)
}
}
}
}
Can anyone help me?
Hello there!
I would like to set an image as the background of my project in SwiftUI, but I have no idea how it is done.
Could anyone help me to figure out this?
I am using Swift Playgrounds and SwiftUI framework.
Hi everyone! I was working on a playground in Swift Playground and I got an error. I can't understand what this error means, can anyone help me?
This is my code:
struct Preview: View {
@State var isPlaying = true
@State var num1 = 60
@State var num2 = 150
var body: some View {
if isPlaying == true { // ERROR: Only concrete types such as structs, enums and classes can conform to protocols
// Required by static method 'buildBlock' where 'C0' = ()
num1 += 1
print("\(num1)")
}
}
}
Thanks.
Hi there! I have a public structure and I called it in my ContentView, but I can't understand where to punt the var/let. I try to put them before "var body: some view" but it gives me these errors.
Hello there! I was trying to build an app with the new App feature in Swift Playgrounds for Mac. But I have an error message in my code, and I can't understand how to fix it. Can anyone help me to solve this error.
Here's the code:
import SwiftUI
struct Something: View {
let rows = 17
let columns = 17
let size: CGFloat = 10
let blocks: [[Color]] = [[.purple, .purple]]
var body: some View {
VStack {
ForEach((0...self.rows - 1), id: \.self) { row in
HStack (spacing: 0) {
ForEach((0...self.columns - 1), id: \.self) { col in
VStack (spacing: 0) {
Rectangle()
.frame(width: self.size, height: self.size)
.foregroundColor(self.blocks[row][col]) // index out of range: the requested index was outside the bounds of the array.
}
}
}
}
}
}
}
Hi developers!
Does anyone know an app to make a short animated film like this https://youtu.be/a4PraWW82_A, which is also free?
I used Procreate before, but there is the layer limit and since my video is a little long I need more layouts :(
thanks in advance
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?
If someone has the right answer, please help me.
Thanks.
Hi guys!
I want to know how can I create an array of UIImage elements and then access these elements randomly?
I tried several times, but I have this issue:
Can someone help me?
Hi everyone!
import SwiftUI
struct ContentView: View {
let screenHeight = UIScreen.main.bounds.height
let letters: [String] = ["A", "B"]
@State private var yOffset: CGFloat = 0.0
var body: some View {
ForEach(letters, id: \.self) { letter in
Text(letter)
.padding()
.font(.largeTitle)
.offset(x: 0, y: yOffset)
.animation(Animation.linear(duration: 5.0).repeatForever(autoreverses: false))
.onAppear {
yOffset = screenHeight - 90
}
}
}
}
I would like in this code, the letters to fall from the beginning of the screen to its end, I have the size of screen's height, but actually I can't understand how I can I use it, until the letters can start from the beginning of the screen. And I would also like that once they reach the bottom, they start falling again...
I can't understand how this effect can be achieved, is there anyone who can help me?
Hi,
I've created an effect that after clicking on the "Hello, world!" button, it has to move (first move is when the user taps on it), and then it has to move again, but this time without any interaction, and it does. But the problem is that when I click again on it, it goes back and then returns to the same position, I can't understand how to solve this issue.
This is my code:
import SwiftUI
public struct ContentView: View {
@State var xPos: CGFloat = 300
@State var yPos: CGFloat = 400
@State var size: CGFloat = 120
public var body: some View {
ZStack {
Image("background")
.resizable()
.frame(width: 700, height: 500)
.padding()
.overlay {
Button(action: {
xPos = 170
yPos = 310
size = 60
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
xPos = 700
}
}) {
Text("Hello, world!")
.font(.system(size: size))
.position(x: xPos, y: yPos)
}
.animation(.spring)
}
}
}
}
Can anyone help me?
Thanks in advance!
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!
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?
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()
}
}