如何编写代码swiftui实现动画效果

如何编写代码swiftui实现动画效果

本篇内容主要讲解“如何编写代码swiftui实现动画效果”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何编写代码swiftui实现动画效果”吧!

withAnimation

import SwiftUI

struct AnimationView: View {

    @State private var showDetail = false
    
    var body: some View {
        Button(action: {
            withAnimation{
                self.showDetail = !self.showDetail
            }
        }) {
            Image(systemName: "chevron.right.circle")
                .imageScale(.large)
                .rotationEffect(.degrees(showDetail ? 90 : 0))
                .scaleEffect(showDetail ? 1.5 : 1)
                .padding()
        }
    }
}

struct AnimationView_Previews: PreviewProvider {
    static var previews: some View {
        AnimationView()
    }
}

到此,相信大家对“如何编写代码swiftui实现动画效果”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!