Skip to content

Commit 376efa7

Browse files
committed
Add "Drawing-and-Animation" > "Drawing-Paths-and-Shapes"
1 parent c604254 commit 376efa7

29 files changed

+751
-8
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// AppDelegate.swift
3+
// Drawing-and-Animation
4+
//
5+
// Created by 王炜 on 2019/6/8.
6+
// Copyright © 2019 Willie. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
@UIApplicationMain
12+
class AppDelegate: UIResponder, UIApplicationDelegate {
13+
14+
15+
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
17+
// Override point for customization after application launch.
18+
return true
19+
}
20+
21+
func applicationWillTerminate(_ application: UIApplication) {
22+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
23+
}
24+
25+
// MARK: UISceneSession Lifecycle
26+
27+
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
28+
// Called when a new scene session is being created.
29+
// Use this method to select a configuration to create the new scene with.
30+
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
31+
}
32+
33+
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
34+
// Called when the user discards a scene session.
35+
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
36+
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
37+
}
38+
39+
40+
}
41+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"images" : [
3+
{
4+
"size" : "20x20",
5+
"idiom" : "iphone",
6+
"filename" : "landmark_app_icon_40x40.png",
7+
"scale" : "2x"
8+
},
9+
{
10+
"idiom" : "iphone",
11+
"size" : "20x20",
12+
"scale" : "3x"
13+
},
14+
{
15+
"size" : "29x29",
16+
"idiom" : "iphone",
17+
"filename" : "landmark_app_icon_58x58.png",
18+
"scale" : "2x"
19+
},
20+
{
21+
"size" : "29x29",
22+
"idiom" : "iphone",
23+
"filename" : "landmark_app_icon_87x87.png",
24+
"scale" : "3x"
25+
},
26+
{
27+
"size" : "40x40",
28+
"idiom" : "iphone",
29+
"filename" : "landmark_app_icon_80x80.png",
30+
"scale" : "2x"
31+
},
32+
{
33+
"size" : "40x40",
34+
"idiom" : "iphone",
35+
"filename" : "landmark_app_icon_120x120.png",
36+
"scale" : "3x"
37+
},
38+
{
39+
"size" : "60x60",
40+
"idiom" : "iphone",
41+
"filename" : "landmark_app_icon_120x120-1.png",
42+
"scale" : "2x"
43+
},
44+
{
45+
"size" : "60x60",
46+
"idiom" : "iphone",
47+
"filename" : "landmark_app_icon_180x180.png",
48+
"scale" : "3x"
49+
},
50+
{
51+
"idiom" : "ipad",
52+
"size" : "20x20",
53+
"scale" : "1x"
54+
},
55+
{
56+
"size" : "20x20",
57+
"idiom" : "ipad",
58+
"filename" : "landmark_app_icon_40x40-1.png",
59+
"scale" : "2x"
60+
},
61+
{
62+
"idiom" : "ipad",
63+
"size" : "29x29",
64+
"scale" : "1x"
65+
},
66+
{
67+
"size" : "29x29",
68+
"idiom" : "ipad",
69+
"filename" : "landmark_app_icon_58x58-1.png",
70+
"scale" : "2x"
71+
},
72+
{
73+
"size" : "40x40",
74+
"idiom" : "ipad",
75+
"filename" : "landmark_app_icon_40x40-2.png",
76+
"scale" : "1x"
77+
},
78+
{
79+
"size" : "40x40",
80+
"idiom" : "ipad",
81+
"filename" : "landmark_app_icon_80x80-1.png",
82+
"scale" : "2x"
83+
},
84+
{
85+
"size" : "76x76",
86+
"idiom" : "ipad",
87+
"filename" : "landmark_app_icon_76x76.png",
88+
"scale" : "1x"
89+
},
90+
{
91+
"size" : "76x76",
92+
"idiom" : "ipad",
93+
"filename" : "landmark_app_icon_152x152.png",
94+
"scale" : "2x"
95+
},
96+
{
97+
"size" : "83.5x83.5",
98+
"idiom" : "ipad",
99+
"filename" : "landmark_app_icon_167x167.png",
100+
"scale" : "2x"
101+
},
102+
{
103+
"size" : "1024x1024",
104+
"idiom" : "ios-marketing",
105+
"filename" : "landmark_app_icon_1024x1024.png",
106+
"scale" : "1x"
107+
}
108+
],
109+
"info" : {
110+
"version" : 1,
111+
"author" : "xcode"
112+
}
113+
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}

Drawing-and-Animation/Badge.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Badge.swift
3+
// Drawing-and-Animation
4+
//
5+
// Created by 王炜 on 2019/6/8.
6+
// Copyright © 2019 Willie. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct Badge: View {
12+
static let rotationCount = 8
13+
14+
var badgeSymbols: some View {
15+
ForEach(0..<Badge.rotationCount) { i in
16+
RotatedBadgeSymbol(
17+
angle: .degrees(Double(i) / Double(Badge.rotationCount)) * 360.0
18+
)
19+
}
20+
.opacity(0.5)
21+
}
22+
23+
var body: some View {
24+
ZStack {
25+
BadgeBackground()
26+
27+
GeometryReader { geometry in
28+
self.badgeSymbols
29+
.scaleEffect(1.0 / 4.0, anchor: .top)
30+
.position(x: geometry.size.width / 2.0, y: (3.0 / 4.0) * geometry.size.height)
31+
}
32+
}
33+
.scaledToFit()
34+
}
35+
}
36+
37+
#if DEBUG
38+
struct Badge_Previews : PreviewProvider {
39+
static var previews: some View {
40+
Badge()
41+
}
42+
}
43+
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// BadgeBackground.swift.swift
3+
// Drawing-and-Animation
4+
//
5+
// Created by 王炜 on 2019/6/8.
6+
// Copyright © 2019 Willie. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct BadgeBackground: View {
12+
var body: some View {
13+
GeometryReader { geometry in
14+
Path { path in
15+
var width: CGFloat = min(geometry.size.width, geometry.size.height)
16+
let height = width
17+
let xScale: CGFloat = 0.832
18+
let xOffset = (width * (1.0 - xScale)) / 2.0
19+
width *= xScale
20+
path.move(
21+
to: CGPoint(
22+
x: xOffset + width * 0.95,
23+
y: height * (0.20 + HexagonParameters.adjustment)
24+
)
25+
)
26+
27+
HexagonParameters.points.forEach {
28+
path.addLine(
29+
to: .init(
30+
x: xOffset + width * $0.useWidth.0 * $0.xFactors.0,
31+
y: height * $0.useHeight.0 * $0.yFactors.0
32+
)
33+
)
34+
35+
path.addQuadCurve(
36+
to: .init(
37+
x: xOffset + width * $0.useWidth.1 * $0.xFactors.1,
38+
y: height * $0.useHeight.1 * $0.yFactors.1
39+
),
40+
control: .init(
41+
x: xOffset + width * $0.useWidth.2 * $0.xFactors.2,
42+
y: height * $0.useHeight.2 * $0.yFactors.2
43+
)
44+
)
45+
}
46+
}
47+
.fill(LinearGradient(
48+
gradient: .init(colors: [Self.gradientStart, Self.gradientEnd]),
49+
startPoint: .init(x: 0.5, y: 0),
50+
endPoint: .init(x: 0.5, y: 0.6)
51+
))
52+
.aspectRatio(1, contentMode: .fit)
53+
}
54+
}
55+
static let gradientStart = Color(red: 239.0 / 255, green: 120.0 / 255, blue: 221.0 / 255)
56+
static let gradientEnd = Color(red: 239.0 / 255, green: 172.0 / 255, blue: 120.0 / 255)
57+
}
58+
59+
60+
#if DEBUG
61+
struct BadgeBackground_Previews: PreviewProvider {
62+
static var previews: some View {
63+
BadgeBackground()
64+
}
65+
}
66+
#endif
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// BadgeSymbol.swift
3+
// Drawing-and-Animation
4+
//
5+
// Created by 王炜 on 2019/6/8.
6+
// Copyright © 2019 Willie. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct BadgeSymbol: View {
12+
static let symbolColor = Color(red: 79.0 / 255, green: 79.0 / 255, blue: 191.0 / 255)
13+
14+
var body: some View {
15+
GeometryReader { geometry in
16+
Path { path in
17+
let width = min(geometry.size.width, geometry.size.height)
18+
let height = width * 0.75
19+
let spacing = width * 0.030
20+
let middle = width / 2
21+
let topWidth = 0.226 * width
22+
let topHeight = 0.488 * height
23+
24+
path.addLines([
25+
CGPoint(x: middle, y: spacing),
26+
CGPoint(x: middle - topWidth, y: topHeight - spacing),
27+
CGPoint(x: middle, y: topHeight / 2 + spacing),
28+
CGPoint(x: middle + topWidth, y: topHeight - spacing),
29+
CGPoint(x: middle, y: spacing)
30+
])
31+
32+
path.move(to: CGPoint(x: middle, y: topHeight / 2 + spacing * 3))
33+
path.addLines([
34+
CGPoint(x: middle - topWidth, y: topHeight + spacing),
35+
CGPoint(x: spacing, y: height - spacing),
36+
CGPoint(x: width - spacing, y: height - spacing),
37+
CGPoint(x: middle + topWidth, y: topHeight + spacing),
38+
CGPoint(x: middle, y: topHeight / 2 + spacing * 3)
39+
])
40+
}
41+
.fill(Self.symbolColor)
42+
}
43+
}
44+
}
45+
46+
#if DEBUG
47+
struct BadgeSymbol_Previews : PreviewProvider {
48+
static var previews: some View {
49+
BadgeSymbol()
50+
}
51+
}
52+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
5+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--View Controller-->
10+
<scene sceneID="EHf-IW-A2E">
11+
<objects>
12+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
13+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
14+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
15+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
16+
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
17+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
18+
</view>
19+
</viewController>
20+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
21+
</objects>
22+
<point key="canvasLocation" x="53" y="375"/>
23+
</scene>
24+
</scenes>
25+
</document>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// ContentView.swift
3+
// Drawing-and-Animation
4+
//
5+
// Created by 王炜 on 2019/6/8.
6+
// Copyright © 2019 Willie. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct ContentView : View {
12+
var body: some View {
13+
Text("Hello World")
14+
}
15+
}
16+
17+
#if DEBUG
18+
struct ContentView_Previews : PreviewProvider {
19+
static var previews: some View {
20+
ContentView()
21+
}
22+
}
23+
#endif

0 commit comments

Comments
 (0)