IOS Swift hello world

测试更新

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// ContentView.swift
// Aaronwei
//
// Created by ylkj on 2022/6/24.
//

import SwiftUI


struct ContentView: View {

@State private var username: String = ""

var body: some View {
VStack {
VStack(spacing: 0){

Form {
TextField(
"请输入用户名",
text: $username
)
.onAppear {
UITextField.appearance().clearButtonMode = .whileEditing
}
.padding(.bottom, -10.0)
.textFieldStyle(.automatic)
}.frame(minHeight: 0, maxHeight: 100)


ScrollView{
VStack{
ButtonView(icon:"applelogo",text:"苹果1")
ButtonView(icon:"applelogo",text:"苹果2")
ButtonView(icon:"applelogo",text:"苹果3")
ButtonView(icon:"applelogo",text:"苹果4")
ButtonView(icon:"applelogo",text:"苹果5")
ButtonView(icon:"applelogo",text:"苹果6")
ButtonView(icon:"applelogo",text:"苹果7")
ButtonView(icon:"applelogo",text:"苹果8")
ButtonView(icon:"applelogo",text:"苹果9")
VStack{
ButtonView(icon:"applelogo",text:"苹果10")
ButtonView(icon:"applelogo",text:"苹果11")
}

}
}


HStack(spacing: 0){
ButtonView(icon:"applelogo",text:"苹果")
ButtonView(icon:"car",text:"特斯拉")
}.zIndex(10)
.frame(alignment: .bottom)
.padding(.bottom,0)
.ignoresSafeArea()
.background(Color.white.opacity(0.3))
.frame(maxHeight: .zero)
}

//
// ButtonView(icon:"applelogo",text:"苹果").padding(.top, -100.0).zIndex(20)
// .frame(alignment: .bottom)
// .ignoresSafeArea()

}

}
}

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




struct ButtonView: View {
var icon :String
var text :String

struct CustomButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(.system(size: 12))
.frame(minWidth: 0, maxWidth: .infinity)
.padding()
.foregroundColor(Color(.white))
.background(Color(red: 88 / 255, green: 224 / 255, blue: 133 / 255))
.cornerRadius(30)
.padding(.horizontal, 10)
.padding(.vertical, 2)
.shadow(radius: 4)
.scaleEffect(configuration.isPressed ? 1.2 : 1)
.animation(.easeInOut(duration: 0.2), value: configuration.isPressed)
}
}

var body: some View {
VStack{
Button(action: {
print("按钮被触发了~")
}){
HStack {
Image(systemName: icon)
.imageScale(.large)
Text(text)
.fontWeight(.semibold)
.font(.title)
}
}
.buttonStyle(CustomButtonStyle())
}
.font(.largeTitle)
}

}
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
//
// AaronListView.swift
// Aaronwei
//
// Created by ylkj on 2023/10/21.
//

import SwiftUI


struct AaronListView_Previews: PreviewProvider {
static var previews: some View {
AaronListView(isPush: .constant(true))
}
}


struct AaronListView: View {
@State var offset: CGSize = .zero
@Binding var isPush : Bool
@State public var showDetailInner = false
@Namespace var nameSpace

@Environment(\.presentationMode) var presentationMode

@State private var username: String = ""

var body: some View {
ZStack(){
if showDetailInner {
withAnimation(.easeInOut){
TestDetailView(showDetailInner:$showDetailInner).padding(0).background(Color.white).zIndex(10).ignoresSafeArea(.all)
}
}else{
VStack{

ButtonDetailView(icon:"applelogo",text:"苹果")

List{
StreetRow(name: "The Lodon Street")

.onTapGesture {
showDetailInner.toggle()
}
}

}.background(Color.white.opacity(0.0))
.scaleEffect(getScale())
.offset(x: self.offset.width > 0 ? self.offset.width :0)
.gesture(DragGesture()
.onChanged{ value in
withAnimation(.spring()) {
offset = value.translation
print(offset)
if(offset.width > 160){
presentationMode.wrappedValue.dismiss()
}
}
}
.onEnded { value in
withAnimation(.spring()) {
offset = .zero
}
}


)
}
}
}

func getScale() -> CGFloat {
let width = UIScreen.main.bounds.width / 2
let offsetX = abs(offset.width)
let percentage = offsetX / width
return 1.0 - min(0.5, percentage)
}
}


struct StreetRow: View {

var name: String
@Namespace var shapeTransition

var body: some View {
HStack(alignment: .center){
Text("1")
.fontWeight(.bold)
.padding()
.background(Color.white)
.foregroundColor(.black)
.clipShape(Circle())
.overlay(Circle().stroke(Color.black, lineWidth: 3))

HStack(alignment: .center){
Image("applelogo").resizable().frame(width: 80, height: 80)
.background(.green)
.clipShape(Circle())
.overlay(Circle().stroke(Color.white, lineWidth: 4))
.shadow(radius: 5)


VStack(alignment: .leading){
Text("Queezy App")
.foregroundColor(Color(red: 50 / 255, green: 50 / 255, blue: 50 / 255))
.fontWeight(.bold)
Text("1888 rmb")
.foregroundColor(.gray)
.padding(.top,1)
}

}.frame(width: 240)
HStack{
Text("2")
.fontWeight(.bold)
.padding()
.background(Color.white)
.cornerRadius(80)
.foregroundColor(.gray)
.clipShape(Circle())
.overlay(Circle().stroke(Color.gray, lineWidth: 3))
}.padding(.leading,10).padding(.top,4)

}

}
}

struct ButtonDetailView: View {
var icon :String
var text :String
@Environment(\.presentationMode) var presentationMode

struct CustomButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(.system(size: 12))
.frame(minWidth: 0, maxWidth: .infinity)
.padding()
.foregroundColor(Color(.white))
.background(Color.green)
.cornerRadius(20)
.padding(.horizontal, 10)
.padding(.vertical, 2)
.shadow(radius: 4)
.scaleEffect(configuration.isPressed ? 1.2 : 1)
.animation(.easeInOut(duration: 0.2), value: configuration.isPressed)
}
}

var body: some View {
VStack{
Button(action: {
presentationMode.wrappedValue.dismiss()
}){
HStack {
Image(systemName: icon)
.imageScale(.large)
Text(text)
.fontWeight(.semibold)
.font(.title)
}
}
.buttonStyle(CustomButtonStyle())
}
.font(.largeTitle)
}

}


struct TestDetailView: View {
@State var offset: CGSize = .zero
@Binding var showDetailInner : Bool
@State var isText = false
@State var offsetN: CGSize = .zero
@State var indexText: Int = 0

@Namespace var shapeTransition1
@Namespace var shapeTransition2
@Namespace var shapeTransition3
@Namespace var shapeTransition4
@Namespace var shapeTransitionD
let menuImages = ["house", "paperplane", "heart", "person.2"]


@Environment(\.presentationMode) var presentationMode
func getScaleN() -> CGFloat {
let width = UIScreen.main.bounds.width / 2
let offsetX = abs(offsetN.width)
let percentage = offsetX / width
return 1.0 - min(0.5, percentage)
}
var body: some View {
ZStack {
if isText {
ZStack(alignment: .topTrailing){
ButtonFLoatView(icon: "applelogo", text: "", isText: $isText).zIndex(500)
.padding(.top,60)
.padding(.trailing,20)
// Rounded Rectangle
VStack(alignment: .center){

Image("applelogo").frame(minWidth: 0, maxWidth: .infinity,minHeight: 0,maxHeight: 400)
.background(.green)
.shadow(radius: 5)
.matchedGeometryEffect(id: "circle1\(indexText)", in: shapeTransition1,isSource: isText)
VStack(alignment: .leading){
Text("Queezy App")
.foregroundColor(Color(red: 50 / 255, green: 50 / 255, blue: 50 / 255))
.fontWeight(.bold)
.matchedGeometryEffect(id: "circle2\(indexText)", in: shapeTransition1,isSource: isText)
Text("1888 rmb")
.foregroundColor(.gray)
.padding(.top,1)
.matchedGeometryEffect(id: "circle3\(indexText)", in: shapeTransition1,isSource: isText)
}

Text("\(indexText)")
.fontWeight(.bold)
.padding()
.background(Color.white)
.cornerRadius(80)
.foregroundColor(.gray)
.clipShape(Circle())
.overlay(Circle().stroke(Color.gray, lineWidth: 3))
.matchedGeometryEffect(id: "circleD\(indexText)", in: shapeTransition1,isSource: isText)
Text("1\(indexText)")
.fontWeight(.bold)
.padding()
.background(Color.white)
.foregroundColor(.black)
.clipShape(Circle())
.overlay(Circle().stroke(Color.black, lineWidth: 3))
.matchedGeometryEffect(id: "circle4\(indexText)", in: shapeTransition1,isSource: isText)
Spacer()

}.onTapGesture {
withAnimation(.easeInOut){
isText.toggle()
}
}.zIndex(10).background(Color.white.opacity(0.4))
.scaleEffect(getScaleN())
.offset(x: self.offsetN.width > 0 ? self.offsetN.width :0)
.gesture(DragGesture()
.onChanged{ value in
withAnimation(.spring()) {
offsetN = value.translation
if(offsetN.width > 180){
isText.toggle()
}else{
offsetN = .zero
}
}
}
.onEnded { value in
withAnimation(.spring()) {
offsetN = .zero
isText = false

}
}


)
}
}else{
VStack{
ForEach(menuImages.indices,id:\.self){ index in
HStack(alignment: .center){
Text("\(index)")
.fontWeight(.bold)
.padding()
.background(Color.white)
.foregroundColor(.black)
.clipShape(Circle())
.overlay(Circle().stroke(Color.black, lineWidth: 3))
.matchedGeometryEffect(id: "circle2\(index)", in: shapeTransition1,isSource: !isText)
HStack(alignment: .center){
Image("applelogo").resizable().frame(width: 80, height: 80)
.background(.green)
.clipShape(Circle())
.overlay(Circle().stroke(Color.white, lineWidth: 4))
.shadow(radius: 5)
.matchedGeometryEffect(id: "circle1\(index)", in: shapeTransition1)

VStack(alignment: .leading){
Text("Queezy App")
.foregroundColor(Color(red: 50 / 255, green: 50 / 255, blue: 50 / 255))
.fontWeight(.bold)
.matchedGeometryEffect(id: "circle3\(index)", in: shapeTransition1,isSource: !isText)
Text("1888 rmb")
.foregroundColor(.gray)
.padding(.top,1)
.matchedGeometryEffect(id: "circle4\(index)", in: shapeTransition1,isSource: !isText)

}

}.frame(width: 240)
HStack{
Text("1\(index)")
.fontWeight(.bold)
.padding()
.background(Color.white)
.cornerRadius(80)
.foregroundColor(.gray)
.clipShape(Circle())
.overlay(Circle().stroke(Color.gray, lineWidth: 3))
.matchedGeometryEffect(id: "circleD\(index)", in: shapeTransition1,isSource: !isText)
}.padding(.leading,10).padding(.top,4)

}.onTapGesture {
withAnimation(.easeInOut){
isText.toggle()
indexText = index
}
}

}
}
}
}
}
}



struct ButtonFLoatView: View {
var icon :String
var text :String
@Binding var isText : Bool

struct CustomButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.frame(width: 30,height: 30)
.font(.system(size: 12))
.foregroundColor(Color(.gray))
.background(Color.white)
.clipShape(Circle())
.shadow(radius: 2)
.scaleEffect(configuration.isPressed ? 1.2 : 1)
.animation(.easeInOut(duration: 0.2), value: configuration.isPressed)
}
}

var body: some View {
VStack{
Button(action: {
withAnimation(.easeInOut){
isText.toggle()
}
}){
VStack {
Image(systemName: icon)
.imageScale(.large)
}
}
.buttonStyle(CustomButtonStyle())
}
.font(.largeTitle)
}

}