拥有easieIn动画,然后随着缩放动画永远重复而按顺序缩放动画 [英] Having easeIn animation and then scale animation in a sequence as the scale animation repeats forever

查看:27
本文介绍了拥有easieIn动画,然后随着缩放动画永远重复而按顺序缩放动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个easeIn/moveUp 动画onAppear 用于文本信息和SF 符号.此后,我只希望 SF 符号永远放大和缩小.目前,我已经设法永远缩小,但是当我设法链接时,easeIn/moveUp 动画也会永远重复自己,它应该只在出现时重复一次.

I want to have a easeIn/moveUp animation onAppear for the text information and SF symbols. Thereafter, I want only the SF symbols to scale up and down forever. Currently, I have managed to scale up down forever but when I managed to chain, the easeIn/moveUp animation also repeated itself forever which should only be repeated once when it appears.

这就是我的应用程序表示的样子:

This is how my app representation looks like:

我在下面包含了一个 pin 动画代码片段:

I have included a snippet of the pin animation code below:

                HStack (spacing: 20) {
                    Image(systemName: "pin")
                        .foregroundColor(.red)
                        .font(.title2)
                        .padding(.trailing, 5)
                        .scaleEffect(animationAmount)
                        .onAppear {
                            let baseAnimation = Animation.easeInOut(duration: 1)
                            let repeated = baseAnimation.repeatForever(autoreverses: true)
                            return withAnimation(repeated) {
                                self.animationAmount = 1.5
                            }
                        }
                    VStack (alignment: .leading) {
                        Text("Pin favourites").fontWeight(.semibold)
                        Text("You can pin your favourite content on all devices")
                            .foregroundColor(.gray)
                    }
                    Spacer()
                }//HStack 2

完整代码在以下页面:SwiftUI - 在工作表中有一个不可滚动的固定继续按钮

推荐答案

你可以加入带有值的动画,如下图

You can join animation with value, like below

.scaleEffect(animationAmount)
.animation(Animation.easeInOut(duration: 1).repeatForever(autoreverses: true), value: animationAmount)
.onAppear {
    self.animationAmount = 1.5
}

此外,由于现在动画和状态是唯一连接的,不会与其他动画/状态发生冲突,您可以将最后两个修饰符移动到最顶部的容器(而不是重复三次)

moreover, as now animation and state joined uniquely and will not conflict with other animations/states, you can move last two modifiers to the very top container (instead of repeating them three times)

例如这里:

}//VStack for 3 criterias
.padding([.leading, .trailing], 20)
.animation(Animation.easeInOut(duration: 1).repeatForever(autoreverses: true), value: animationAmount)
.onAppear {
    self.animationAmount = 1.5
}

这篇关于拥有easieIn动画,然后随着缩放动画永远重复而按顺序缩放动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆