Skip to content

Commit f0292e9

Browse files
authored
Merge pull request Jinxiansen#24 from SpRoom/master
# Added `lottery`.
2 parents 1a475e1 + 435181c commit f0292e9

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

Example/.DS_Store

6 KB
Binary file not shown.

Example/Example.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
36F7ED9F2465231100CF20CB /* LotteryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36F7ED9E2465231100CF20CB /* LotteryView.swift */; };
11+
36F7EDA12465265200CF20CB /* LotteryControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36F7EDA02465265200CF20CB /* LotteryControl.swift */; };
1012
4132A45E22AD561500A8DBBE /* GroupPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4132A45D22AD561500A8DBBE /* GroupPage.swift */; };
1113
4132A46022AD624700A8DBBE /* SectionPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4132A45F22AD624700A8DBBE /* SectionPage.swift */; };
1214
4132A46322AD709300A8DBBE /* Color+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4132A46222AD709300A8DBBE /* Color+Ext.swift */; };
@@ -51,6 +53,8 @@
5153
/* End PBXBuildFile section */
5254

5355
/* Begin PBXFileReference section */
56+
36F7ED9E2465231100CF20CB /* LotteryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LotteryView.swift; sourceTree = "<group>"; };
57+
36F7EDA02465265200CF20CB /* LotteryControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LotteryControl.swift; sourceTree = "<group>"; };
5458
4132A45D22AD561500A8DBBE /* GroupPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupPage.swift; sourceTree = "<group>"; };
5559
4132A45F22AD624700A8DBBE /* SectionPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionPage.swift; sourceTree = "<group>"; };
5660
4132A46222AD709300A8DBBE /* Color+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Ext.swift"; sourceTree = "<group>"; };
@@ -107,6 +111,15 @@
107111
/* End PBXFrameworksBuildPhase section */
108112

109113
/* Begin PBXGroup section */
114+
36F7ED9D246522E000CF20CB /* Lottery */ = {
115+
isa = PBXGroup;
116+
children = (
117+
36F7ED9E2465231100CF20CB /* LotteryView.swift */,
118+
36F7EDA02465265200CF20CB /* LotteryControl.swift */,
119+
);
120+
path = Lottery;
121+
sourceTree = "<group>";
122+
};
110123
4132A46122AD700F00A8DBBE /* Container */ = {
111124
isa = PBXGroup;
112125
children = (
@@ -223,6 +236,7 @@
223236
4196ABE522AA24B4008B8FD2 /* Page */ = {
224237
isa = PBXGroup;
225238
children = (
239+
36F7ED9D246522E000CF20CB /* Lottery */,
226240
4160444F22B2985D0052CAFC /* SpecialPage */,
227241
41FE99ED22AADF7C008135A0 /* Text */,
228242
41FE99EE22AADF8E008135A0 /* Image */,
@@ -350,7 +364,9 @@
350364
41E4DCD022B4B4FF00F78522 /* ActionSheetPage.swift in Sources */,
351365
4196ABC822A97AB1008B8FD2 /* AppDelegate.swift in Sources */,
352366
4161B33222AB6D3400CD5A1B /* ForEachPage.swift in Sources */,
367+
36F7EDA12465265200CF20CB /* LotteryControl.swift in Sources */,
353368
41977FF522ACA74600FD47FE /* WebImagePage.swift in Sources */,
369+
36F7ED9F2465231100CF20CB /* LotteryView.swift in Sources */,
354370
4196ABE722AA268A008B8FD2 /* TextFieldPage.swift in Sources */,
355371
4161B32722AB68F600CD5A1B /* HStackPage.swift in Sources */,
356372
D74985BC231634DA00C4D46D /* Window+Ext.swift in Sources */,

Example/Example/ContentView.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ struct ContentView : View {
1313
var body: some View {
1414
NavigationView {
1515
List {
16+
Section(header: Text("Animation")) {
17+
NavigationLink(destination: LotteryView()) {
18+
PageRow(title: "LotteryView", subTitle: "Rotation Lottery")
19+
}
20+
}
1621
Section(header: Text("特殊视图")) {
1722
NavigationLink(destination: WebViewPage()) {
1823
PageRow(title: "WebView", subTitle: "用于展示一个打开的网页")
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// LotteryControl.swift
3+
// Example
4+
//
5+
// Created by xj on 2020/5/8.
6+
// Copyright © 2020 晋先森. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class LotteryControl: ObservableObject {
12+
@Published var rotation = 0.0
13+
var index = 8
14+
var angle: Double {
15+
360 / Double(index)
16+
}
17+
init() {
18+
print("init runed")
19+
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { (timer) in
20+
self.rotation += 30
21+
}
22+
}
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// LotteryView.swift
3+
// Example
4+
//
5+
// Created by xj on 2020/5/8.
6+
// Copyright © 2020 晋先森. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct LotteryView: View {
12+
13+
@ObservedObject var control = LotteryControl()
14+
15+
let colors = [Color.red, .black, .gray, .green, .blue, .orange, .yellow, .purple]
16+
17+
var body: some View {
18+
ZStack {
19+
ForEach(0..<control.index, id: \.self) { idx in
20+
Path { path in
21+
path.move(to: CGPoint(x: 150, y: 150))
22+
path.addArc(center: CGPoint(x: 150, y: 150), radius: 150, startAngle: Angle(degrees: Double(idx) * self.control.angle), endAngle: Angle(degrees: Double(idx+1) * self.control.angle), clockwise: false)
23+
path.addLine(to: CGPoint(x: 150, y: 150))
24+
}.fill(self.colors[idx%self.colors.count])
25+
}
26+
}.frame(width: 300, height: 300, alignment: .center).rotationEffect(.degrees(control.rotation))
27+
}
28+
}
29+
30+
struct LotteryView_Previews: PreviewProvider {
31+
32+
static var previews: some View {
33+
LotteryView().frame(width: 300, height: 300, alignment: .center)
34+
}
35+
}
36+

0 commit comments

Comments
 (0)