为什么此脉动动画会移动x和y位置?

问题描述

我想要的是Text()视图,该视图可以无限地就地进行缩放。我所拥有的是可以在缩放的同时还可以移动x和y位置。我不明白。

如何在不移动x / y的情况下按比例放大和缩小?

感谢您的帮助!

struct ContentView: View {
    @State private var pulsate: Bool = false
    
    var body: some View {
        GeometryReader { geo in
        Text("Hello,World!")
            .foregroundColor(Color.black)
            .multilineTextAlignment(.center)
            .position(x: geo.size.width * 0.12,y: geo.size.height * 0.05)
            .shadow(radius: 2)
            .scaleEffect(self.pulsate ? 1.0 : 1.05)
            .animation(Animation.easeInOut(duration: 1).repeatForever(autoreverses: true).speed(1))
            .onAppear() {
                self.pulsate.toggle()
            }
        }
    }
}

解决方法

修饰符的位置很重要。就您而言,应该在动画之后不受影响,如

File::open