struct Study_lecture20: View {
@State var show = false
var body: some View {
ZStack{
Color.blue.ignoresSafeArea()
.opacity(show ? 0.5 : 0.2)
.animation(.linear(duration: 0.8))
RoundedRectangle(cornerRadius: 40)
.foregroundColor(.white)
.frame(height: 300)
.padding(show ? 16 : 32)
.offset(y: show ? 0 : 30)
//여기까지는 spring 애니메이션 적용됨
.animation(.spring(response: 0.6, dampingFraction: 0.01))
.opacity(show ? 1 : 0.5)
//위 오패시티는 리니어 애니메이션 적용됨.
.animation(.linear(duration: 0.5))
//response : 무게감 / dampingFraction : 유연성
}
.onTapGesture {
show.toggle()
}
}
}
Swift
복사