I want to make this animation but it’s not working.
How can I do this animation?
When I use this in a new project it’s working but in this project it is not working.
struct SULoveCompatibilityLoadingView: View {
var body: some View {
ZStack{
Color(ThemeManager.pageBackgroundColor()).ignoresSafeArea()
VStack{
Spacer()
HStack(alignment: .center, spacing: 0){
VStack{
Image(signIcon)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 110, height: 110)
Spacer().frame(height: 15)
Text(userName)
.font(Font.custom("SanFranciscoText-Bold", size: 18))
Spacer().frame(height: 3)
Text(signName)
.font(Font.custom("SanFranciscoText-Regular", size: 14))
}
Spacer()
VStack{
Image(systemName: "heart.fill")
.foregroundColor(.red)
.scaleEffect(isAnimating ? 1.3 : 1.0)
.onAppear {
withAnimation(.easeInOut(duration: 0.4).repeatForever(autoreverses: true)) {
self.isAnimating.toggle()
}
}
.font(.system(size: 50))
}
.padding()
Spacer()
VStack{
Image("Onur")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 110, height: 110)
Spacer().frame(height: 15)
Text(friendName)
.font(Font.custom("SanFranciscoText-Bold", size: 18))
Spacer().frame(height: 3)
Text("Onur")
.font(Font.custom("SanFranciscoText-Regular", size: 14))
}
}
.frame(height: 200)
Spacer()
}
}
}
}
This is what I am wanting:
And this is what happened:
2
Answers
It works when I create a new project, but it doesn't work in SwiftUI that I added to the UIKit project.
I added a @State property named isAnimating to control the heart animation separately. The withAnimation block now only applies to the heart image, preventing the entire VStack from shaking. Adjust the animation parameters as needed.