-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnowFlakeView.swift
More file actions
43 lines (38 loc) · 1.22 KB
/
Copy pathSnowFlakeView.swift
File metadata and controls
43 lines (38 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// SnowFlakeView.swift
// AnimationExamples
//
// Created by Esat Gözcü on 2023/03/13.
//
import SwiftUI
struct SnowFlakeView: View {
@StateObject var viewModel = SnowFlakeVM()
@State var action = false
var body: some View {
GeometryReader { geo in
ForEach(0..<viewModel.itemSize, id: \.self) { id in
Image("snow_flake")
.resizable()
.frame(width: viewModel.randomSize[id],
height: viewModel.randomSize[id]
)
.offset(x: viewModel.randomXList[id],
y: action ? geo.size.height : 0 - viewModel.randomSize[id]
)
.animation(
.linear(duration: Double(viewModel.randomDurationMillis[id])/1000)
.delay(Double(viewModel.randomDelayMillis[id])/1000)
.repeatCount(10, autoreverses: false)
)
}
}.ignoresSafeArea()
.onAppear{
action = true
}
}
}
struct SnowFlakeView_Preview: PreviewProvider {
static var previews: some View {
SnowFlakeView()
}
}