@@ -2270,224 +2270,209 @@ Swift 里的结构体和其他语言类似
2270
2270
2271
2271
555
2272
2272
00:23:28,440 --> 00:23:29,860
2273
- This is not object-oriented programming.
2273
+ 这不是面向对象编程
2274
2274
2275
2275
556
2276
2276
00:23:29,860 --> 00:23:31,450
2277
- This is functional programming.
2277
+ 这是函数式编程
2278
2278
2279
2279
557
2280
2280
00:23:31,450 --> 00:23:33,410
2281
- And that's why we may be more likely
2281
+ 这也是为什么我们更倾向于
2282
2282
2283
2283
558
2284
2284
00:23:33,410 --> 00:23:36,680
2285
- to say something like a
2286
- ContentView functions like a View
2285
+ 说 ContentView 像 View 一样运作
2287
2286
2288
2287
559
2289
2288
00:23:36,680 --> 00:23:39,290
2290
- or it behaves like a View.
2289
+ 或者它的行为像 View
2291
2290
2292
2291
560
2293
2292
00:23:39,290 --> 00:23:41,330
2294
- And this is super important.
2293
+ 这是非常重要的
2295
2294
2296
2295
561
2297
2296
00:23:41,330 --> 00:23:44,680
2298
- This behavior, View, is crucial
2297
+ 你会发现 View 这个行为
2299
2298
2300
2299
562
2301
2300
00:23:44,680 --> 00:23:47,810
2302
- to how all of SwiftUI
2303
- works as you will see.
2301
+ 是 SwiftUI 实现中非常关键的
2304
2302
2305
2303
563
2306
2304
00:23:47,810 --> 00:23:49,950
2307
- We are going to be using so many Views
2305
+ 我们将会使用非常多的 View
2308
2306
2309
2307
564
2310
2308
00:23:49,950 --> 00:23:53,320
2311
- in the next couple of lectures,
2312
- you can't even imagine it.
2309
+ 在接下来的几节课中
2310
+ 你甚至都想象不到有多少
2313
2311
2314
2312
565
2315
2313
00:23:53,320 --> 00:23:55,730
2316
- And we're gonna talk
2317
- all about the concepts
2314
+ 通过第二节课开始的幻灯片
2318
2315
2319
2316
566
2320
2317
00:23:55,730 --> 00:23:59,110
2321
- behind this behavior specification
2318
+ 我们也会讨论声明这个行为
2322
2319
2323
2320
567
2324
2321
00:23:59,110 --> 00:24:01,650
2325
- using slides at the
2326
- beginning of lecture two.
2322
+ 背后所有的概念
2327
2323
2328
2324
568
2329
2325
00:24:01,650 --> 00:24:03,870
2330
- In the meantime, we're
2331
- just going to understand
2326
+ 同时,现在我们只要理解
2332
2327
2333
2328
569
2334
2329
00:24:03,870 --> 00:24:07,133
2335
- that this means that
2336
- ContentView behaves like a View.
2330
+ 这个意思是 ContentView
2331
+ 有 View 一样的行为
2337
2332
2338
2333
570
2339
2334
00:24:07,980 --> 00:24:11,390
2340
- A View is just a
2341
- rectangular area on screen.
2335
+ 一个 View 只是屏幕上的一个长方形区域
2342
2336
2343
2337
571
2344
2338
00:24:11,390 --> 00:24:14,280
2345
- So here I've put my mouse on this Text
2339
+ 这里我把鼠标放在这个 Text 上
2346
2340
2347
2341
572
2348
2342
00:24:14,280 --> 00:24:15,853
2349
- and it's selected it
2350
- over here in the preview.
2343
+ 它就在这边预览里被选中了
2351
2344
2352
2345
573
2353
2346
00:24:15,853 --> 00:24:19,970
2354
- And you can see it's put this
2355
- blue border around that Text.
2347
+ 你可以看到这里 Text 的周围有蓝色边框
2356
2348
2357
2349
574
2358
2350
00:24:19,970 --> 00:24:22,310
2359
- That blue border is bordering this View.
2351
+ 那个蓝色边框就是这个 View 的边界
2360
2352
2361
2353
575
2362
2354
00:24:22,310 --> 00:24:25,210
2363
- So a Text, it also behaves like a View.
2355
+ 所以 Text 也有 View 一样的行为
2364
2356
2365
2357
576
2366
2358
00:24:25,210 --> 00:24:26,520
2367
- It "is a" View.
2359
+ 它也“是”个 View
2368
2360
2369
2361
577
2370
2362
00:24:26,520 --> 00:24:28,120
2371
- And so you're seeing it right here.
2363
+ 所以你能在这里看到它
2372
2364
2373
2365
578
2374
2366
00:24:28,120 --> 00:24:29,440
2375
- So that's all Views are.
2367
+ 这就是 View
2376
2368
2377
2369
579
2378
2370
00:24:29,440 --> 00:24:31,610
2379
- They're rectangular areas on screen,
2371
+ 它们是屏幕上的长方形区域
2380
2372
2381
2373
580
2382
2374
00:24:31,610 --> 00:24:34,560
2383
- both for drawing and also for multi-touch.
2375
+ 既用于显示,也支持多点触控
2384
2376
2385
2377
581
2386
2378
00:24:34,560 --> 00:24:37,870
2387
- For swipes and taps, pinches,
2379
+ 滑动、点击、缩放
2388
2380
2389
2381
582
2390
2382
00:24:37,870 --> 00:24:41,120
2391
- those kinds of things
2392
- happen in these rectangles.
2383
+ 这类操作都在这个长方形里面发生
2393
2384
2394
2385
583
2395
2386
00:24:41,120 --> 00:24:42,640
2396
- So that's what a View is.
2387
+ 所以这就是 View
2397
2388
2398
2389
584
2399
2390
00:24:42,640 --> 00:24:44,670
2400
- So when something behaves like a View,
2391
+ 当一个东西有 View 一样的行为
2401
2392
2402
2393
585
2403
2394
00:24:44,670 --> 00:24:46,330
2404
- it's a rectangular area on screen.
2395
+ 它就是屏幕上一个长方形的区域
2405
2396
2406
2397
586
2407
2398
00:24:46,330 --> 00:24:49,250
2408
- So our ContentView which
2409
- behaves like a View
2399
+ 我们的 ContentView 有 View 一样的行为
2410
2400
2411
2401
587
2412
2402
00:24:49,250 --> 00:24:51,900
2413
- is this entire rectangle.
2403
+ 它就是这里的一整个长方形
2414
2404
2415
2405
588
2416
2406
00:24:51,900 --> 00:24:54,640
2417
- The whole rectangle that fills the screen
2407
+ 充满屏幕的整个长方形
2418
2408
2419
2409
589
2420
2410
00:24:54,640 --> 00:24:56,173
2421
- is our ContentView.
2411
+ 就是我们的 ContentView
2422
2412
2423
2413
590
2424
2414
00:24:57,296 --> 00:24:59,890
2425
- All right, if you are somebody,
2415
+ 如果你是
2426
2416
2427
2417
591
2428
2418
00:24:59,890 --> 00:25:02,260
2429
- some struct like this ContentView,
2419
+ 比如像这个 ContentView 一样的结构体
2430
2420
2431
2421
592
2432
2422
00:25:02,260 --> 00:25:05,320
2433
- and you want to say that
2434
- you behave like a View,
2423
+ 且你想有 View 一样的行为
2435
2424
2436
2425
593
2437
2426
00:25:05,320 --> 00:25:10,320
2438
- you must in your struct
2439
- have this var right here,
2427
+ 在你的结构体中必须有这个变量
2440
2428
2441
2429
594
2442
2430
00:25:10,360 --> 00:25:12,850
2443
- this var called body.
2431
+ 这个叫做 body 的变量
2444
2432
2445
2433
595
2446
2434
00:25:12,850 --> 00:25:14,330
2447
- I'll select it for you here.
2435
+ 就是我这里选中的这个
2448
2436
2449
2437
596
2450
2438
00:25:14,330 --> 00:25:17,190
2451
- So here's the declaration of var body.
2439
+ 这里就是变量 body 的声明
2452
2440
2453
2441
597
2454
2442
00:25:17,190 --> 00:25:20,890
2455
- So Swift variables, they
2456
- have the keyword var,
2443
+ Swift 的变量使用关键词 var
2457
2444
2458
2445
598
2459
2446
00:25:20,890 --> 00:25:22,210
2460
- short for variable.
2447
+ 单词 variable 的缩写
2461
2448
2462
2449
599
2463
2450
00:25:22,210 --> 00:25:24,910
2464
- Although we don't tend to call variables
2451
+ 尽管在一个结构体中
2465
2452
2466
2453
600
2467
2454
00:25:24,910 --> 00:25:27,700
2468
- inside a struct like this vars.
2455
+ 我们一般不称它为变量
2469
2456
2470
2457
601
2471
2458
00:25:27,700 --> 00:25:29,770
2472
- We call them properties.
2459
+ 我们把它们称为属性
2473
2460
2474
2461
602
2475
2462
00:25:29,770 --> 00:25:32,870
2476
- So you're gonna hear me use
2477
- the word property all the time.
2463
+ 你们将会一直听我使用属性这个词
2478
2464
2479
2465
603
2480
2466
00:25:32,870 --> 00:25:36,010
2481
- It means a var inside a struct or a class.
2467
+ 它的意思是类或者结构体中的变量
2482
2468
2483
2469
604
2484
2470
00:25:36,010 --> 00:25:38,120
2485
- Also, if we're doing
2486
- object-oriented programming,
2471
+ 如果我们做面向对象编程
2487
2472
2488
2473
605
2489
2474
00:25:38,120 --> 00:25:40,210
2490
- we call them properties.
2475
+ 我们把它们称为属性
2491
2476
2492
2477
606
2493
2478
00:25:40,210 --> 00:25:44,680
0 commit comments