-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13. Timer and Animation.srt
9264 lines (7412 loc) · 209 KB
/
13. Timer and Animation.srt
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1
00:00:00,401 --> 00:00:04,468
[MUSIC]
(音乐)
2
00:00:04,537 --> 00:00:07,571
Stanford University,
斯坦福大学,
3
00:00:07,640 --> 00:00:11,675
>> Okay, well, welcome to Stanford CS193P,
> >好的,好吧,欢迎来到斯坦福CS193P,
4
00:00:11,744 --> 00:00:16,346
Developing Applications for iOS, Winter 2017,
iOS应用程序开发,2017年冬天,
5
00:00:16,415 --> 00:00:18,915
this is lecture number 13,
这是13号的讲座,
6
00:00:18,984 --> 00:00:23,253
And this week's topic is gonna be animation, and
本周的主题是动画,和
7
00:00:23,322 --> 00:00:27,290
I'm gonna talk first today about timers,
今天我要谈谈关于计时器,
8
00:00:27,359 --> 00:00:30,426
Timer is just a way to execute a block of code,
定时器是一个执行一块代码,
9
00:00:30,495 --> 00:00:33,028
some periodic amount of time,
一些周期性的时间,
10
00:00:33,097 --> 00:00:35,830
We don't really use timers for animation per se,
我们真的不为动画本身使用定时器,
11
00:00:35,899 --> 00:00:39,167
but often, when we're doing something that's animated,
但通常,当我们做一些动画,
12
00:00:39,236 --> 00:00:41,168
we'll have some timers involved,
我们会有一些计时器,
13
00:00:41,237 --> 00:00:44,038
And you'll see that especially on Wednesday's big demo,
你会看到,特别是周三的演示,大
14
00:00:44,107 --> 00:00:47,675
how we're gonna use the timer in with our animation tools,
我们要如何使用定时器在与我们的动画工具,
15
00:00:47,743 --> 00:00:49,609
Then after we talk about timer, I,
之后我们讨论计时器,我,
16
00:00:49,678 --> 00:00:53,146
I do a demo there, we're gonna dive into animation proper,
我做一个演示,我们将深入的动画,
17
00:00:53,214 --> 00:00:56,216
And I'm gonna talk about all the different kinds of
我要谈论的所有不同类型的
18
00:00:56,284 --> 00:00:59,619
animation mechanisms there are and then dive into,
动画机制有深入,
19
00:00:59,687 --> 00:01:02,421
a couple of them with a bit of a demo in between,
两个之间有一个演示,
20
00:01:02,490 --> 00:01:05,357
And then on Wednesday, I'll do a demo of the last animation
然后周三,我会做一个最后的动画演示
21
00:01:05,426 --> 00:01:07,359
style, that I'm gonna cover,
风格,我要盖,
22
00:01:08,828 --> 00:01:12,930
So timer, timer is this, very simple class,
这是计时器,计时器,非常简单的类,
23
00:01:12,999 --> 00:01:13,830
very simple to use,
很简单的使用,
24
00:01:13,899 --> 00:01:15,732
You're only probably gonna use two or
你只可能会使用两个或两个
25
00:01:15,801 --> 00:01:19,035
maybe three, methods or vars in it ever,
也许三个,或var方法,
26
00:01:19,104 --> 00:01:21,604
And all it allows you to do is take a closure,
和所有你可以做的是把一个闭包,
27
00:01:21,672 --> 00:01:24,674
a block of code, and execute it some time in the future,
一块代码,执行它在未来的某个时间,
28
00:01:24,743 --> 00:01:28,476
either once or repeatedly, in the future,
一次或者多次,在未来,
29
00:01:28,545 --> 00:01:33,715
And, this is kind of not really real-time programming,
这是种不实时编程,
30
00:01:33,783 --> 00:01:36,484
This timer's not gonna go off exactly when you say, but
这个定时器不会离开什么时候你会说,但是
31
00:01:36,553 --> 00:01:39,154
it's gonna be pretty close because it's going off on
它会很接近,因为它在
32
00:01:39,222 --> 00:01:39,987
the main queue,
主要的队列,
33
00:01:40,056 --> 00:01:41,789
And the main queue is sometimes is busy
和主要的队列有时很忙
34
00:01:41,858 --> 00:01:44,024
handling an event or something like that,
处理一个事件或类似的东西,
35
00:01:44,092 --> 00:01:45,024
So it's not exact, but
这不是准确的,但是
36
00:01:45,093 --> 00:01:46,859
it's pretty darn close, to going off,
很接近,会,
37
00:01:46,928 --> 00:01:49,862
So you can't use it for real time programming, but you can,
所以你不能用它来实时编程,但是你可以,
38
00:01:49,931 --> 00:01:53,465
use it to have any kind of repeating thing going on,
使用它有任何重复的东西,
39
00:01:53,534 --> 00:01:55,900
Now, timer is based on a technology,
现在,计时器是基于一项技术,
40
00:01:55,969 --> 00:01:59,103
which I'm not gonna talk about called run loops,
我不会谈论称为循环运行,
41
00:01:59,172 --> 00:02:02,941
And run loops are how, you know, a certain thread gets
和运行循环是如何,你知道,一个特定的线程
42
00:02:03,009 --> 00:02:07,111
all this information, like events from the, touch screen
所有这些信息,如事件,触摸屏
43
00:02:07,179 --> 00:02:11,148
and, or, you know, events from the network, or whatever,
或者,你知道,来自网络的事件,等等,
44
00:02:11,217 --> 00:02:13,851
It gets all these things coming in, and it manages to
就这些东西进来,它管理
45
00:02:13,919 --> 00:02:16,986
hand them all out to whoever needs to handle them,
手,谁需要处理它们,
46
00:02:17,055 --> 00:02:19,289
And run loops aren't super complicated, but
和运行循环不是超级复杂,但是
47
00:02:19,357 --> 00:02:21,791
the reason I don't really talk about them is the run loop
我真的不谈论他们的原因是运行循环
48
00:02:21,860 --> 00:02:23,525
just kinda works on the main queue, and
只是有点主队列工作,
49
00:02:23,594 --> 00:02:25,427
you don't really need to think about it,
你真的不需要考虑,
50
00:02:25,496 --> 00:02:27,061
But if you ever find yourself,
但如果你发现自己,
51
00:02:27,130 --> 00:02:29,698
I wanna use a timer off the main queue, then you're gonna
我想用一个计时器主要队列,然后你会
52
00:02:29,766 --> 00:02:31,865
have to teach yourself about run loops, okay,
要自学运行循环,好吧,
53
00:02:31,934 --> 00:02:35,202
because the timers are totally based, on the run loop,
因为计时器是基于完全的,运行循环,
54
00:02:35,271 --> 00:02:37,755
your purposes in this course as a starting, iOS developer,
你的目的在本课程开始,iOS开发者,
55
00:02:37,756 --> 00:02:40,240
But for
但对于
56
00:02:40,308 --> 00:02:44,677
you can assume that timers are a main queue thing, okay?
你可以假设定时器队列是一个主要的事情,好吗?
57
00:02:44,746 --> 00:02:46,779
Now, there's really, there's,
现在,有真的,还有,
58
00:02:46,847 --> 00:02:49,415
you can create timers by instantiating them,
您可以创建计时器通过实例化它们,
59
00:02:49,483 --> 00:02:52,417
but then you gotta put them on a run loop and all that,
但是你必须把它们放在一个运行循环,
60
00:02:52,486 --> 00:02:54,819
But, so there's really just one method,
但是,这只是一种方法,
61
00:02:54,888 --> 00:02:56,921
class method you're gonna use in timer,
类方法你会使用定时器,
62
00:02:56,990 --> 00:03:01,325
And what this one method does is it takes a block of code,
这一方法是需要一块代码,
63
00:03:01,393 --> 00:03:02,910
And it takes how, when you wanna execute it some time in
需要如何,当你想执行一段时间
64
00:03:02,911 --> 00:03:04,428
a closure,
一个闭包,
65
00:03:04,496 --> 00:03:07,730
the future and whether you wanna keep repeating executing
未来,你是否想要一直重复执行
66
00:03:07,799 --> 00:03:09,598
it, and it goes and does that,
它,,,,
67
00:03:09,667 --> 00:03:11,934
It puts the thing on the run loop to make sure that it
它将运行循环上的事以确保它
68
00:03:12,003 --> 00:03:14,736
executes that block of code with that interval,
执行的代码块的间隔,
69
00:03:14,805 --> 00:03:17,906
Really couldn't be simpler, it's a very, very, simple and
真的不能再简单了,这是一个非常,非常简单
70
00:03:17,975 --> 00:03:19,307
powerful UI right there,
强大的UI,
71
00:03:19,376 --> 00:03:22,810
So down at the bottom, here's an example of it,
所以在底部,这里有一个例子,
72
00:03:22,879 --> 00:03:25,279
this method is called scheduled timer,
调用此方法将定时器,
73
00:03:25,348 --> 00:03:28,048
And it returns the timer that it creates when it schedules
它返回计时器,它创建时间表
74
00:03:28,117 --> 00:03:30,116
it and puts it on the run loop,
他们会把它运行循环,
75
00:03:30,185 --> 00:03:32,218
And so here I'm just saying timer =,
所以我只是说计时器=,
76
00:03:32,287 --> 00:03:33,619
I have a local var timer,
我有一个当地的var计时器,
77
00:03:33,688 --> 00:03:35,955
Notice it's of type timer, it's an optional timer here,
通知类型的计时器,它是一个可选的定时器,
78
00:03:36,023 --> 00:03:38,724
And so I do timer = scheduledTimer(withTimeInter-
所以我做计时器= scheduledTimer(withTimeInter -
79
00:03:38,792 --> 00:03:41,126
val: 2,0, repreat, repeats: true),
瓦尔:2 0 repreat重复:真正的),
80
00:03:41,195 --> 00:03:42,794
And then the block, I put some code,
然后,我把一些代码,
81
00:03:42,862 --> 00:03:45,663
Well, that's gonna execute that code two seconds from now
这是要执行这段代码两秒
82
00:03:45,732 --> 00:03:46,797
approximately,
约,
83
00:03:46,866 --> 00:03:48,098
And since it's repeats true,
因为它的重复正确的,
84
00:03:48,166 --> 00:03:50,066
it's gonna execute it again two seconds later and
它会再次两秒后,执行它
85
00:03:50,135 --> 00:03:53,736
then two seconds after that until I stop this thing, okay?
后两秒,直到我停止这个东西,好吗?
86
00:03:53,805 --> 00:03:57,573
Now, one thing to note about this little example here,
现在,有一件事需要注意这个小例子,
87
00:03:57,642 --> 00:03:59,575
is notice my timer is weak,
是注意到我的计时器是弱,
88
00:04:00,577 --> 00:04:01,943
Okay, see that, weak?
好的,看到,软弱?
89
00:04:02,012 --> 00:04:03,644
Why do I make that timer weak?
为什么我让计时器弱?
90
00:04:03,713 --> 00:04:05,646
Well, when I scheduled this timer, and
当我预定这个定时器
91
00:04:05,715 --> 00:04:06,914
it puts it on the run loop,
它把它的运行循环,
92
00:04:06,983 --> 00:04:09,583
the run loop is gonna grab a strong reference to it,
运行循环会抓住一个强引用,
93
00:04:09,652 --> 00:04:11,585
So I don't need a strong reference to it,
所以我不需要一个强引用,
94
00:04:11,654 --> 00:04:14,320
And in fact, if I make my reference weak, then when
事实上,如果我让我的弱引用,当
95
00:04:14,389 --> 00:04:17,223
this run loop is done with it, when this thing finally
这样做循环运行,当这件事最终
96
00:04:17,292 --> 00:04:20,392
stops running, my ti, timer var there will be set to nil,
停止运行,ti,计时器var设置为零,
97
00:04:20,461 --> 00:04:21,693
Perfect, exactly what I want,
完美的,正是我想要的,
98
00:04:21,762 --> 00:04:24,029
because it's really no use tabbing a pointer to this
因为它没有使用列表的指针
99
00:04:24,097 --> 00:04:26,231
timer if it's not running anymore,
计时器如果不运行了,
100
00:04:26,300 --> 00:04:28,266
And if I ever wanted to start a timer up again
如果我想启动一个计时器
101
00:04:28,334 --> 00:04:30,901
that I'd stopped, I would just call scheduledTimer again,
我停止了,我就叫scheduledTimer再一次,
102
00:04:30,970 --> 00:04:33,337
it's such a simple, API,
这样一个简单的API,
103
00:04:34,640 --> 00:04:35,872
So how do you stop a timer?
那么如何停止计时器?
104
00:04:35,940 --> 00:04:38,307
So you got a timer and it's got repeating true and
所以你有一个计时器,它有重复的真实
105
00:04:38,376 --> 00:04:39,241
it's going off and
它会和
106
00:04:39,310 --> 00:04:42,110
it's doing this closure every two seconds or whatever,
做这个闭包每两秒,
107
00:04:42,179 --> 00:04:45,147
You stop it by sending the message invalidate to
你停止它通过发送消息无效
108
00:04:45,215 --> 00:04:49,117
the timer, and so invalidate tells the run loop to stop,
定时器,所以无效告诉运行循环停止,
109
00:04:49,186 --> 00:04:52,921
scheduling this thing and invalidates the timer,
调度和无效计时器,
110
00:04:52,989 --> 00:04:55,556
Now, again, this timer is going to not, if you do
现在,这个计时器,如果你做的事情
111
00:04:55,625 --> 00:04:58,492
invalidate right there, and you have a weak var to it,
无效,你有一个弱的var,
112
00:04:58,561 --> 00:05:01,862
it's gonna go out of the heap, which is really convenient,
它会出去堆的,很方便,
113
00:05:04,132 --> 00:05:05,564
There's one last thing I'm gonna do about timers,
还有最后一件事我要做关于计时器,
114
00:05:05,633 --> 00:05:07,166
which is tolerance,
这是宽容,
115
00:05:07,234 --> 00:05:10,603
So this is not a real-time thing, and you might be quite
这不是一个实时的事情,你可能会相当
116
00:05:10,671 --> 00:05:13,805
tolerant of it not executing exactly on time,
宽容不是按时执行,
117
00:05:13,873 --> 00:05:16,440
This makes more sense for timers that take longer, like
这对定时器,需要更长的时间更有意义,
118
00:05:16,509 --> 00:05:18,576
let's say you have a timer that goes off every minute,
假设您有一个计时器,每一分钟,
119
00:05:18,644 --> 00:05:19,643
and it does something,
做了一些,
120
00:05:19,712 --> 00:05:22,579
Well, you might be happy if it goes off 50 seconds from now
好吧,你可能会快乐如果离开50秒
121
00:05:22,648 --> 00:05:23,880
or 70 seconds from now,
或从现在开始70秒,
122
00:05:23,949 --> 00:05:26,883
So you would set a tolerance of 10 on the timer, and
所以你会设定一个宽容的10的计时器
123
00:05:26,952 --> 00:05:30,286
it means it'll go off in the window plus or minus that 10,
这意味着它会离开在±10的窗口中,
124
00:05:30,355 --> 00:05:32,721
By the way, this does not have any drift,
顺便说一下,这没有任何漂移,
125
00:05:32,790 --> 00:05:35,624
So, if it, if the system decided it was gonna go off in
所以,如果,如果系统决定是要离开
126
00:05:35,693 --> 00:05:40,062
50 seconds this time, the next time, it wouldn't, you know,
50秒这一次,下一次,它不会,你知道,
127
00:05:40,130 --> 00:05:42,197
be shorter and shorter and shorter with each time,
是越来越短和更短的时间,
128
00:05:42,265 --> 00:05:44,999
So, the time it goes off is the amount of time from
所以,时间的流逝的时间是
129
00:05:45,068 --> 00:05:46,267
the time you started the timer,
当你开始定时器,
130
00:05:46,336 --> 00:05:47,701
Even if it's two days later,
即使是两天后,
131
00:05:47,770 --> 00:05:50,036
it's still going off once per minute,
还是去一次每分钟
132
00:05:50,105 --> 00:05:51,938
It's once per minute since you started the timer,
这是每分钟一次,因为你开始定时器,
133
00:05:52,007 --> 00:05:53,506
It's just that when it goes off, it'll be plus or
只是当它响起时,它会加或
134
00:05:53,575 --> 00:05:55,341
minus a little bit each time,
每次减一点,
135
00:05:55,410 --> 00:05:58,377
Now why would you want to tell the system this?
为什么你想告诉系统呢?
136
00:05:58,446 --> 00:06:01,346
Well, when your timer goes off, you know,
好吧,当你的时间到了,你知道,
137
00:06:01,415 --> 00:06:03,381
it might be that the system is actually asleep,
这可能是系统实际上是睡着了,
138
00:06:03,450 --> 00:06:06,116
Your phone surprisingly sleeps a little,
你的手机意外睡一点点,
139
00:06:06,185 --> 00:06:09,854
takes a little micro naps all the time, okay, to save power,
需要一点微小睡,好的,节省电力,
140
00:06:09,923 --> 00:06:11,955
especially to save battery,
尤其是为了节省电池,
141
00:06:12,024 --> 00:06:13,857
And wakes up every once in a while, and
和醒来每隔一段时间,
142
00:06:13,925 --> 00:06:16,593
it kinda knows when it's gonna wake up again,
它知道什么时候会再次醒来,
143
00:06:16,661 --> 00:06:19,629
And so the tolerance allows it to maybe take a micro nap
所以宽容使得它也许午睡微
144
00:06:19,698 --> 00:06:22,731
a little longer cuz it's gonna wake up for something else,
一段时间因为别的东西就会醒来,
145
00:06:22,800 --> 00:06:24,399
and then it could be your timer,
然后它会成为你计时器,
146
00:06:24,468 --> 00:06:27,468
You see, so this is a little micro performance,
你看,这是一个小的性能,
147
00:06:27,537 --> 00:06:28,469
But if you have something to go on and
但是如果你继续
148
00:06:28,538 --> 00:06:30,471
off every minute over, you know,
每一分钟,你知道,
149
00:06:30,540 --> 00:06:32,606
long periods of time, it can add up,
很长一段时间,它可以增加,
150
00:06:32,675 --> 00:06:35,375
Okay, so that's tolerance,
好了,这是宽容,
151
00:06:35,444 --> 00:06:37,444
All right, so, let's do a little demo,
好吧,那么,让我们做一个演示,
152
00:06:37,512 --> 00:06:40,613
see this in action, it's kinda obvious, once you see it,
看到这个动作,它有点明显,一旦你看到它,
153
00:06:40,682 --> 00:06:43,415
So I'm gonna take FaceIt, remember the FaceIt demo we
所以我要把FaceIt,记住我们FaceIt演示
154
00:06:43,484 --> 00:06:45,151
had, this is a picture of a face,
这是一个一脸的照片,
155
00:06:45,219 --> 00:06:47,953
I'm gonna make the eyes blink using a timer, okay?
我要让眼睛眨使用一个计时器,好吗?
156
00:06:48,022 --> 00:06:49,420
The timer's just gonna open the eyes and
计时器就会打开眼睛和
157
00:06:49,489 --> 00:06:51,556
then close the eyes, open the eyes and then close the eyes,
然后闭上眼睛,睁开眼睛,然后关闭的眼睛,
158
00:06:51,625 --> 00:06:53,291
super simple,
超级简单,
159
00:06:53,359 --> 00:06:57,362
So let's go back and get FaceIt, here it is,
所以让我们回过头来得到FaceIt,在这里,
160
00:06:58,898 --> 00:07:02,432
All right, so here is our face view now,
好吧,这是我们现在面临视图,
161
00:07:02,501 --> 00:07:03,966
The thing about the blinking, I'm gonna,
的闪烁,我要
162
00:07:04,035 --> 00:07:06,169
I wanna show you this again because it's so important,
我想给你看一遍,因为它是如此的重要,
163
00:07:06,237 --> 00:07:08,538
I'm gonna actually put this blinking code in a separate
我要把这闪烁的代码在一个单独的
164
00:07:08,606 --> 00:07:11,273
view controller, which is a sub class of the other one,
视图控制器,它是一个接头的另一个阶级,
165
00:07:11,342 --> 00:07:14,376
So we have this existing FaceViewController right here
所以我们这里的现有FaceViewController
166
00:07:14,445 --> 00:07:19,146
as the thing that controls this MBC right here, okay?
作为控制这里的MBC的东西,好吗?
167
00:07:19,215 --> 00:07:21,983
Where this face is, it's, it's loading up the face right now,
这张脸在哪里,它加载面对现在,
168
00:07:22,051 --> 00:07:25,119
And so I could just put this code in FaceViewController,
所以我可以把这段代码在FaceViewController,
169
00:07:25,188 --> 00:07:27,120
but just to show you it again, this,
只是给你看一遍,
170
00:07:27,189 --> 00:07:30,457
this thing of, sub-classing another MBC to make one,
这个东西的,生成子类另一个MBC,
171
00:07:30,526 --> 00:07:32,825
I'm gonna create a new FaceViewController called
我要创建一个新的FaceViewController称
172
00:07:32,894 --> 00:07:34,427
a blinking FaceViewController,
一个闪烁的FaceViewController,
173
00:07:34,496 --> 00:07:36,895
I'm gonna put all my blinking code, into that,
我要把我所有的闪烁的代码,,
174
00:07:36,964 --> 00:07:42,434
So let's just go File > New > File, and Cocoa Touch Class,
让我们去File > New >文件,和可可触摸类,
175
00:07:42,503 --> 00:07:44,937
And I'm, it's a subclass of FaceViewController,
而我,FaceViewController的子类,
176
00:07:45,005 --> 00:07:48,907
And I'm gonna call it BlinkingFaceViewController,
我要叫它BlinkingFaceViewController,
177
00:07:48,976 --> 00:07:51,275
And that's gonna create a new class,
要创建一个新类,
178
00:07:51,344 --> 00:07:53,344
I'll put it in same place everything else is,
我把其他的都是在同一个地方,
179
00:07:55,281 --> 00:07:58,515
Okay, here it is, just delete all the code in here, again,
好吧,在这儿,只是删除所有的代码在这里,再一次,
180
00:07:58,584 --> 00:08:01,451
just not to, so as not to distract you,
不是,为了不让你分心,
181
00:08:01,520 --> 00:08:04,420
And you can see that it is a subclass of FaceViewController
你可以看到它是FaceViewController的一个子类
182
00:08:04,489 --> 00:08:07,757
which is this thing right here that has all our stuff in it,
就是这里,我们所有的东西,
183
00:08:07,825 --> 00:08:09,892
And all the code that I'm gonna put inside here is
和所有的代码,我将在这里
184
00:08:09,961 --> 00:08:12,060
only gonna be for blinking,
只会闪烁,
185
00:08:12,128 --> 00:08:13,395
And I'm gonna change,
我要改变,
186
00:08:13,463 --> 00:08:16,564
in my storyboard I'm gonna select this MVC down here and
在我的故事板我会选择下面这个MVC和
187
00:08:16,633 --> 00:08:19,466
right now, its identity is FaceViewController,
现在,它的身份是FaceViewController,
188
00:08:19,535 --> 00:08:22,169
And I'm gonna change it to be a BlinkingFaceViewController,
我将改变它BlinkingFaceViewController,
189
00:08:22,238 --> 00:08:24,437
And that change alone is gonna make it so
改变就会让它如此
190
00:08:24,506 --> 00:08:28,141
that this particular face view right there is going to blink,
这这个脸视图会眨眼,
191
00:08:29,310 --> 00:08:31,910
So how do we do that, how do we make this
那么我们怎么做,我们如何使这
192
00:08:31,979 --> 00:08:33,279
BlinkingFaceViewController work?
BlinkingFaceViewController工作吗?
193
00:08:33,347 --> 00:08:35,013
Well, what's going to be its model?
嗯,它的模型是什么?
194
00:08:35,082 --> 00:08:37,515
Well, its model is going to be public and
嗯,是公众和其模型
195
00:08:37,584 --> 00:08:39,584
I'm gonna call it blinking, and
我要叫它闪烁
196
00:08:39,652 --> 00:08:43,921
it's just gonna be a whether or not we're blinking, okay?
只是要我们是否闪烁,好吗?
197
00:08:43,990 --> 00:08:48,291
And if someone sets this model of this blinking controller
如果有人集模型,这闪烁的控制器
198
00:08:48,360 --> 00:08:53,096
then I'm going to call some method like blinkIfNeeded,
然后我要像blinkIfNeeded调用一些方法,
199
00:08:53,165 --> 00:08:54,998
blinkIfNeeded, private func blinkIfNeeded,
blinkIfNeeded,私人func blinkIfNeeded,
200
00:08:54,999 --> 00:08:56,832
okay?
好吧?