日期Date和DateFormatter日期的格式化

iShot20220409 上午11.32.45.png

iShot20220409 上午11.38.48.png

日历Calendar和日期组件DateComponents

iShot20220409 下午12.06.47.png

日历Calendar和时区TimeZone

iShot20220409 下午11.10.03.png

使用定时组件Timer执行定时任务

import SwiftUI

struct ContentView: View {
    @State private var count :Int = 20
    var body: some View {
        ZStack {
            Color.white.edgesIgnoringSafeArea(.all)
            ForEach(0..<count){ index in
                AnimatedCircle(index: index)
            }
            Text("ZYP Code And PPT!")
                .font(.largeTitle)
                .fontWeight(.medium)
                .foregroundColor(.black)
            .padding(.top,600)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct AnimatedCircle:View{
    @State var index :Int
    @State private var animate : Bool = true
    @State private var yOffsetValue:CGFloat = -200
    
    var body: some View{
        Circle()
            .stroke(lineWidth: 2)
            .frame(width: 20 + CGFloat(index * 15))
            .foregroundColor(.black)
            .rotation3DEffect(.degrees(75), axis:(x:1,y:0,z:0))
            .offset(y:animate ? yOffsetValue: 0)
            .animation(Animation.easeInOut(duration: 2.0).delay(0.1*Double(index)))
            .onAppear(){
                animatedCircle()
                Timer.scheduledTimer(withTimeInterval: 6, repeats: true){ _ in
                   animatedCircle()
                }
            }
    }
    
    func animatedCircle(){
        DispatchQueue.main.asyncAfter(deadline: .now()){
            animate.toggle()
            yOffsetValue = 0
        }
        DispatchQueue.main.asyncAfter(deadline: .now()+1){
            animate.toggle()
            yOffsetValue = 200
        }
        DispatchQueue.main.asyncAfter(deadline: .now()+3){
            animate.toggle()
            yOffsetValue = 0
            
            DispatchQueue.main.asyncAfter(deadline: .now()+1){
                animate.toggle()
                yOffsetValue = -200
            }
        }
    }
}

效果演示

Q.E.D.