-
Notifications
You must be signed in to change notification settings - Fork 48
/
213.srt
4262 lines (3126 loc) · 93.1 KB
/
213.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
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:00:00.506 --> 00:00:10.596 A:middle
[ Silence ]
00:00:11.096 --> 00:00:11.976 A:middle
>> Chris Dreessen:
Good afternoon.
00:00:12.516 --> 00:00:16.286 A:middle
[ Applause ]
00:00:16.786 --> 00:00:18.166 A:middle
Welcome to session 213.
00:00:18.166 --> 00:00:20.196 A:middle
This is best practices
for Cocoa Animation.
00:00:20.356 --> 00:00:21.486 A:middle
I'm Chris Dreessen.
00:00:21.486 --> 00:00:24.996 A:middle
I'm an AppKit Engineer
so I work on this stuff.
00:00:24.996 --> 00:00:26.956 A:middle
We have a lot of great things
we'd like to show you here.
00:00:26.956 --> 00:00:30.126 A:middle
So I'm going to give you
a basic overview of this.
00:00:30.676 --> 00:00:33.086 A:middle
So I said a lot of great things,
I meant a lot of great things.
00:00:33.746 --> 00:00:36.706 A:middle
I'm going to start with a
brief overview of how Animation
00:00:36.706 --> 00:00:38.056 A:middle
in Cocoa works, how to use it.
00:00:38.056 --> 00:00:39.616 A:middle
We're going to continue
to describe how
00:00:39.616 --> 00:00:42.356 A:middle
to make your own view
subclasses animatable
00:00:42.356 --> 00:00:45.006 A:middle
for your own properties
and describe how to augment
00:00:45.006 --> 00:00:47.076 A:middle
that with context
sensitive animations.
00:00:47.806 --> 00:00:49.546 A:middle
I'm going to share
with you a technique I
00:00:49.546 --> 00:00:51.806 A:middle
like to call chaining animations
where we use the completion
00:00:51.806 --> 00:00:54.776 A:middle
of one animation to start
off another animation.
00:00:55.466 --> 00:00:57.826 A:middle
Some of you are familiar
00:00:57.826 --> 00:00:59.956 A:middle
with the implicit
animation functionality
00:00:59.956 --> 00:01:02.286 A:middle
of NSAnimation Contest
we added in 10.8
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:00:59.956 --> 00:01:02.286 A:middle
of NSAnimation Contest
we added in 10.8
00:01:02.286 --> 00:01:04.146 A:middle
and I'm going to cover that.
00:01:04.146 --> 00:01:05.996 A:middle
And then I'm going to cover
a bit of Core Animation,
00:01:05.996 --> 00:01:07.906 A:middle
not how you can use
Core Animation
00:01:08.296 --> 00:01:10.616 A:middle
but rather how NSView
uses Core Animation
00:01:10.616 --> 00:01:12.286 A:middle
to do animations
for layer back use.
00:01:12.636 --> 00:01:13.756 A:middle
At that point I'm going
00:01:13.756 --> 00:01:17.346 A:middle
to invite my colleague Peter
Amman onstage and he's going
00:01:17.346 --> 00:01:19.516 A:middle
to talk about this great new
class called NSStackView.
00:01:19.516 --> 00:01:22.326 A:middle
He's going to describe how
you can use auto layout
00:01:22.326 --> 00:01:23.416 A:middle
to animate view positions,
00:01:23.416 --> 00:01:25.976 A:middle
how you can animate those
constraints directly
00:01:26.176 --> 00:01:27.676 A:middle
and additionally best practices
00:01:27.676 --> 00:01:29.596 A:middle
for animating window
size changes.
00:01:31.246 --> 00:01:33.586 A:middle
So throughout the course of
this presentation I'm going
00:01:33.586 --> 00:01:36.186 A:middle
to be talking a lot about
the NSAnimatableProperty
00:01:36.186 --> 00:01:39.786 A:middle
ContainerProtocol and that lives
in the NSAnimimation.h header.
00:01:40.176 --> 00:01:42.796 A:middle
And it's a simple protocol, it's
just five methods but I'm going
00:01:42.796 --> 00:01:43.916 A:middle
to be coming back here a lot
00:01:43.916 --> 00:01:45.496 A:middle
and we'll touch each
of these one by one.
00:01:46.766 --> 00:01:49.986 A:middle
So basic animations, most of
you are familiar with this
00:01:50.626 --> 00:01:52.916 A:middle
but this is how you animate
basic things for NSView.
00:01:53.996 --> 00:01:55.736 A:middle
So back to NSAnimatableProperty
Container,
00:01:55.736 --> 00:01:57.196 A:middle
I said we'd be coming
back here a lot.
00:01:57.196 --> 00:01:57.636 A:middle
I didn't lie.
00:01:57.636 --> 00:02:00.336 A:middle
The method I want to introduce
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:01:57.636 --> 00:02:00.336 A:middle
The method I want to introduce
00:02:00.336 --> 00:02:02.436 A:middle
to you here is the animator
method which returns
00:02:02.436 --> 00:02:04.296 A:middle
to you the thing we
call the animator proxy.
00:02:04.776 --> 00:02:07.586 A:middle
And this is an object that
implements all the same methods
00:02:07.626 --> 00:02:08.666 A:middle
that your object does.
00:02:09.186 --> 00:02:11.836 A:middle
The difference is when you
message it it will animate them
00:02:11.866 --> 00:02:13.586 A:middle
instead of just popping
to the final location.
00:02:14.646 --> 00:02:16.886 A:middle
So suppose you want to
fade the Alpha of a view.
00:02:16.886 --> 00:02:17.806 A:middle
You want this to disappear?
00:02:18.586 --> 00:02:20.736 A:middle
Well that's not too bad,
that's just one line of code.
00:02:20.736 --> 00:02:22.956 A:middle
We set the Alpha value to zero
through the animator proxy,
00:02:23.026 --> 00:02:26.636 A:middle
view.animator.alphavalue=0
and that's all it takes.
00:02:27.256 --> 00:02:29.116 A:middle
And here's something
more complicated.
00:02:29.116 --> 00:02:33.146 A:middle
This is, we're sliding, that's
got to be way more code, right?
00:02:34.796 --> 00:02:37.536 A:middle
Same thing,
view.animator.frameorigin,
00:02:37.836 --> 00:02:38.886 A:middle
just one line of code again.
00:02:39.766 --> 00:02:42.636 A:middle
Okay here's one more,
we resized it.
00:02:42.636 --> 00:02:43.626 A:middle
That's two dimensions.
00:02:43.626 --> 00:02:45.416 A:middle
That's got to be
four times the work
00:02:45.696 --> 00:02:46.906 A:middle
and it is four times the work.
00:02:46.906 --> 00:02:49.876 A:middle
It's also one line of code.
00:02:50.936 --> 00:02:52.316 A:middle
[laughter] Alright so you're
all familiar with that.
00:02:52.316 --> 00:02:56.246 A:middle
I want to talk about how to make
your own views animatable now.
00:02:56.816 --> 00:02:59.546 A:middle
So suppose you want to do
an animation like this.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:03:00.316 --> 00:03:03.476 A:middle
We have a framed view which is
a single red line on the outside
00:03:03.476 --> 00:03:05.566 A:middle
and we change the line
thickness, we grow it.
00:03:06.116 --> 00:03:07.426 A:middle
So your view might
look like this.
00:03:07.426 --> 00:03:09.486 A:middle
You're going to declare a
line thickness property,
00:03:09.646 --> 00:03:10.456 A:middle
it's a float.
00:03:10.876 --> 00:03:12.476 A:middle
And you're going to
go in and drawRect
00:03:12.476 --> 00:03:13.696 A:middle
and this is a simple drawRect.
00:03:14.056 --> 00:03:17.286 A:middle
We just set the red color and
then we frame our own bounds
00:03:17.506 --> 00:03:19.996 A:middle
with a rectangle of the
appropriate line thickness.
00:03:20.716 --> 00:03:22.456 A:middle
And additionally in our accessor
00:03:22.456 --> 00:03:25.656 A:middle
for setLineThickness we
call setNeedsDisplay yes,
00:03:25.656 --> 00:03:27.436 A:middle
after we've updated our I-bar.
00:03:27.796 --> 00:03:30.226 A:middle
So I told you, you know, you
can just use the animator proxy,
00:03:30.226 --> 00:03:31.286 A:middle
that works fantastically.
00:03:31.676 --> 00:03:34.526 A:middle
And if we try this we
see this animation.
00:03:35.096 --> 00:03:38.436 A:middle
And technically that
was an animation.
00:03:38.436 --> 00:03:39.906 A:middle
Things changed on screen.
00:03:39.906 --> 00:03:41.916 A:middle
But I don't think any of
us are really satisfied
00:03:41.916 --> 00:03:42.696 A:middle
with that animation.
00:03:43.316 --> 00:03:44.096 A:middle
So what was missing?
00:03:45.076 --> 00:03:48.116 A:middle
Well back to the NS Animatable
Property Container Protocol.
00:03:48.386 --> 00:03:50.816 A:middle
There is this method called
defaultAnimationForKey.
00:03:51.316 --> 00:03:52.256 A:middle
It's a class method.
00:03:53.476 --> 00:03:54.856 A:middle
And that is our missing
piece here.
00:03:55.506 --> 00:03:57.766 A:middle
And to make this animatable
we're going to go ahead
00:03:57.766 --> 00:03:59.956 A:middle
and implement the
defaultAnimationForKey method.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:04:00.746 --> 00:04:02.466 A:middle
So our implementation we start
00:04:02.466 --> 00:04:04.766 A:middle
by checking what key we're
actually talking about here.
00:04:05.136 --> 00:04:06.836 A:middle
In this case it's our
line thickness property
00:04:06.836 --> 00:04:07.436 A:middle
which is great.
00:04:07.876 --> 00:04:11.706 A:middle
And we return the default
CABasicAnimationObject
00:04:12.016 --> 00:04:14.366 A:middle
and CABasicAnimation is one
00:04:14.366 --> 00:04:16.426 A:middle
of the animation types
we use most frequently.
00:04:16.426 --> 00:04:19.766 A:middle
It just has very simple
from and to values along
00:04:19.766 --> 00:04:20.495 A:middle
with some properties
00:04:20.495 --> 00:04:22.666 A:middle
that control how those
values are interpolated.
00:04:23.116 --> 00:04:26.286 A:middle
And of course if it's not the
line thickness property we want
00:04:26.286 --> 00:04:27.186 A:middle
to fall through as a super
00:04:27.186 --> 00:04:29.716 A:middle
so the other view properties
can continue being animatable.
00:04:30.406 --> 00:04:33.606 A:middle
And just by adding that if we
do view.animator.linethickness
00:04:33.606 --> 00:04:36.456 A:middle
again we get this animation
which is just what we wanted.
00:04:38.316 --> 00:04:40.526 A:middle
So that's still pretty simple
00:04:40.526 --> 00:04:43.426 A:middle
so let's complicate
things a little bit.
00:04:43.426 --> 00:04:45.556 A:middle
Sometimes you need to
know more information
00:04:45.556 --> 00:04:46.926 A:middle
that you can provide
in a class method.
00:04:46.926 --> 00:04:49.036 A:middle
You need to know what
specifically is being animated.
00:04:49.636 --> 00:04:52.416 A:middle
And you can do that too with MS
Animatable Property Container.
00:04:53.056 --> 00:04:55.176 A:middle
There is a method
called setAnimations
00:04:55.176 --> 00:04:56.176 A:middle
which takes a dictionary,
00:04:56.676 --> 00:04:58.626 A:middle
the keys in the dictionary
are the properties
00:04:58.626 --> 00:05:00.486 A:middle
that are being changed
and the values
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:04:58.626 --> 00:05:00.486 A:middle
that are being changed
and the values
00:05:00.486 --> 00:05:03.056 A:middle
in the dictionary are
CAAnimationObjects describing
00:05:03.056 --> 00:05:04.306 A:middle
how you want us to change them.
00:05:05.806 --> 00:05:09.746 A:middle
So this is our method here
and suppose we wanted to snap
00:05:09.946 --> 00:05:12.116 A:middle
to multiples of 10
for our line thickness
00:05:12.116 --> 00:05:13.386 A:middle
as we did our animation.
00:05:13.776 --> 00:05:15.326 A:middle
We can't really do this here.
00:05:15.326 --> 00:05:16.386 A:middle
There's no way of specifying.
00:05:16.386 --> 00:05:18.526 A:middle
We don't know what the from
and to values are inside
00:05:18.526 --> 00:05:20.556 A:middle
of the class
defaultAnimationForKeyMethod.
00:05:22.016 --> 00:05:24.166 A:middle
So the way we fix
that is we're going
00:05:24.166 --> 00:05:25.906 A:middle
to use this thing called
CAKeyframeAnimation
00:05:25.906 --> 00:05:28.706 A:middle
and the key frame animation is
another animation type we use
00:05:28.706 --> 00:05:29.146 A:middle
a lot.
00:05:29.426 --> 00:05:32.576 A:middle
And in it you can, well
basically you specify values
00:05:32.576 --> 00:05:34.616 A:middle
to the key frames and you
can interpolate between those
00:05:34.616 --> 00:05:37.126 A:middle
or just have it use
those discreet values
00:05:37.126 --> 00:05:38.006 A:middle
at different time stamps.
00:05:38.356 --> 00:05:41.786 A:middle
And in this case we're going to
populate it with steps from 0
00:05:41.786 --> 00:05:43.886 A:middle
to 40 moving by 10 each time.
00:05:44.726 --> 00:05:49.776 A:middle
So once we create our animation
we turn it into a dictionary
00:05:49.886 --> 00:05:52.006 A:middle
and we set it on the
view.animationsproperty
00:05:52.366 --> 00:05:55.046 A:middle
and that's our new objective
C dictionary syntax there.
00:05:55.046 --> 00:05:56.676 A:middle
We specify the key
as line fitness.
00:05:56.726 --> 00:05:58.096 A:middle
The value is our
key frame animation.
00:05:58.486 --> 00:06:00.586 A:middle
And then we just talk to the
animator like we always did.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:05:58.486 --> 00:06:00.586 A:middle
And then we just talk to the
animator like we always did.
00:06:00.716 --> 00:06:04.396 A:middle
View.animator.linefitness=40
and we wind up with an animation
00:06:04.396 --> 00:06:07.716 A:middle
that looks like this instead,
which is exactly what we wanted.
00:06:07.716 --> 00:06:09.816 A:middle
So that's kind of cool.
00:06:10.256 --> 00:06:11.786 A:middle
But there's a few
other things you can do
00:06:11.786 --> 00:06:13.336 A:middle
with key frame animations
that are neat.
00:06:14.076 --> 00:06:17.246 A:middle
And I mentioned you could, you
know you have your key points
00:06:17.246 --> 00:06:18.766 A:middle
in there that have
specific values.
00:06:18.766 --> 00:06:20.306 A:middle
You don't need to interpolate
between those values.
00:06:20.306 --> 00:06:22.336 A:middle
And in fact with some types
of values you can interpolate.
00:06:22.816 --> 00:06:25.926 A:middle
So in this example I'm setting
these values to an array
00:06:25.926 --> 00:06:31.296 A:middle
of images of various Apple
products and the same as before,
00:06:31.296 --> 00:06:34.346 A:middle
I set the animations dictionary
there using our new animation
00:06:34.436 --> 00:06:36.446 A:middle
for the image property, in
this case this could be the an
00:06:36.486 --> 00:06:38.316 A:middle
NSImageView which
implements an image property.
00:06:38.636 --> 00:06:41.186 A:middle
And I just tell the animator
hey, change the image
00:06:41.186 --> 00:06:43.096 A:middle
to this final Apple TV image.
00:06:43.096 --> 00:06:44.436 A:middle
And something I want
to point out,
00:06:44.706 --> 00:06:47.786 A:middle
my key frame animation
specified five different types
00:06:47.786 --> 00:06:49.976 A:middle
of Apple products but it
didn't specify Apple TV.
00:06:50.586 --> 00:06:51.506 A:middle
And the reason for this is
00:06:51.506 --> 00:06:54.946 A:middle
that the value you tell your
animator proxy is the value
00:06:54.946 --> 00:06:57.106 A:middle
that's going to wind up
in the object ultimately.
00:06:57.566 --> 00:07:00.746 A:middle
The stuff in the animation
is just used along the way.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:06:57.566 --> 00:07:00.746 A:middle
The stuff in the animation
is just used along the way.
00:07:00.966 --> 00:07:04.156 A:middle
So if we see what this
looks like, recycling nicely
00:07:04.156 --> 00:07:05.876 A:middle
through the Apple
products in our image well,
00:07:05.876 --> 00:07:07.246 A:middle
and we end at Apple TV.
00:07:07.766 --> 00:07:09.046 A:middle
And you can do this
with other things.
00:07:09.046 --> 00:07:10.026 A:middle
You don't need to do
it with just images.
00:07:10.026 --> 00:07:11.636 A:middle
You can do it with string
values, for example.
00:07:11.636 --> 00:07:12.856 A:middle
In this case we have
a text field.
00:07:13.606 --> 00:07:15.386 A:middle
Our values are various
city names.
00:07:16.956 --> 00:07:19.146 A:middle
And again, if we set the
animations dictionary
00:07:19.146 --> 00:07:22.376 A:middle
on our text field using string
value this time as the key
00:07:22.686 --> 00:07:25.366 A:middle
and our key frame
animation again as the value,
00:07:25.436 --> 00:07:27.286 A:middle
and finally we tell
the animator,
00:07:27.286 --> 00:07:29.296 A:middle
hey your string value is San
Francisco because we want
00:07:29.296 --> 00:07:31.156 A:middle
to wind up in San
Francisco and all
00:07:31.156 --> 00:07:33.366 A:middle
of you here have already
completed the step, good job.
00:07:34.476 --> 00:07:35.506 A:middle
So we see what that looks like.
00:07:35.506 --> 00:07:37.816 A:middle
It animates our text field
just like we expected.
00:07:38.636 --> 00:07:40.466 A:middle
But you can do a
few more things.
00:07:40.466 --> 00:07:42.146 A:middle
You don't need to
restrict yourself
00:07:42.146 --> 00:07:43.146 A:middle
to key frame animations.
00:07:43.906 --> 00:07:47.066 A:middle
So if you're familiar
with NSCell and NSControl,
00:07:47.066 --> 00:07:49.096 A:middle
especially NSTextField,
you're familiar
00:07:49.096 --> 00:07:50.706 A:middle
with these things
we call formatters.
00:07:51.666 --> 00:07:55.436 A:middle
And formatters are objects which
take an arbitrary object type
00:07:55.476 --> 00:07:57.316 A:middle
and return a human
readable string value.
00:07:58.176 --> 00:07:59.346 A:middle
And in this case I'm going
00:07:59.346 --> 00:08:00.766 A:middle
to implement my own
formatter class,
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:07:59.346 --> 00:08:00.766 A:middle
to implement my own
formatter class,
00:08:00.766 --> 00:08:03.596 A:middle
in this case the cleverly named
my formatter but we're going
00:08:03.596 --> 00:08:05.896 A:middle
to delegate most of our
actual formatting work
00:08:06.176 --> 00:08:06.826 A:middle
to NSDateFormatter.
00:08:08.326 --> 00:08:10.356 A:middle
So our string for object
value method looks like this,
00:08:10.356 --> 00:08:13.556 A:middle
we take in an NS number and we
just ask for its double value.
00:08:13.556 --> 00:08:16.276 A:middle
And one of the ways we
represent dates on our system is
00:08:16.276 --> 00:08:18.906 A:middle
as the number of seconds
since January 1, 2001,
00:08:18.936 --> 00:08:21.546 A:middle
that's the reference dater,
in this case the time interval
00:08:21.546 --> 00:08:22.626 A:middle
since the reference date.
00:08:23.076 --> 00:08:25.256 A:middle
And we can construct a new date
00:08:25.326 --> 00:08:26.996 A:middle
from that double value
representing the number
00:08:26.996 --> 00:08:27.426 A:middle
of seconds.
00:08:27.426 --> 00:08:29.926 A:middle
And then we just plug
this into our NSFormatter
00:08:29.926 --> 00:08:32.976 A:middle
and it gives us a nice human
readable string for the date.
00:08:33.655 --> 00:08:35.285 A:middle
And we couple that
with this code.
00:08:35.506 --> 00:08:38.186 A:middle
We go ahead, and I want this to
be a long, slow animation for us
00:08:38.216 --> 00:08:40.056 A:middle
to savor so it could
take 20 seconds.
00:08:40.496 --> 00:08:42.556 A:middle
And here I'm replacing
the animations dictionary
00:08:42.556 --> 00:08:43.596 A:middle
on the text field again,
00:08:43.986 --> 00:08:45.616 A:middle
this time for the
double value property.
00:08:45.616 --> 00:08:47.396 A:middle
Double value is a property most
00:08:47.396 --> 00:08:49.166 A:middle
of our controls themselves
implement,
00:08:49.396 --> 00:08:51.666 A:middle
and again it's a double so
it's easily interpolatable
00:08:51.666 --> 00:08:53.076 A:middle
using CABasicAnimation.
00:08:53.966 --> 00:08:57.116 A:middle
I set the text field's double
value to the initial value of 0
00:08:57.116 --> 00:08:58.786 A:middle
and then I ramp it
up to 1,000,000.
00:08:59.566 --> 00:09:02.146 A:middle
And when you do this
you get this animation.
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:08:59.566 --> 00:09:02.146 A:middle
And when you do this
you get this animation.
00:09:03.046 --> 00:09:06.186 A:middle
We are actually formatting
the interpolated values
00:09:06.186 --> 00:09:10.116 A:middle
for every second between January
1, 2001 and wherever this ends.
00:09:10.896 --> 00:09:13.316 A:middle
So you can also use
this for other things,
00:09:13.316 --> 00:09:15.426 A:middle
for example you can implement
your own double property
00:09:15.426 --> 00:09:18.026 A:middle
that we can interpolate because
it's a double and say ramp it
00:09:18.026 --> 00:09:20.426 A:middle
between 0 and 1 and then
use that as the input
00:09:20.426 --> 00:09:24.036 A:middle
to your own calculation to do a
more complicated interpolation.
00:09:24.296 --> 00:09:26.006 A:middle
And yes, I love you
so much I dug
00:09:26.006 --> 00:09:28.136 A:middle
up the old Chicago font
for that animation.
00:09:29.036 --> 00:09:34.606 A:middle
[applause] So we're going to get
00:09:34.606 --> 00:09:37.826 A:middle
into something I call chaining
animations now which is simple
00:09:37.826 --> 00:09:39.926 A:middle
but can look complicated.
00:09:39.926 --> 00:09:43.726 A:middle
Don't be daunted by this
next slide, that one.
00:09:43.726 --> 00:09:45.066 A:middle
You can be daunted by
this slide, that's okay.
00:09:45.986 --> 00:09:49.016 A:middle
So in this case we just
have a few animation groups.
00:09:49.426 --> 00:09:50.796 A:middle
So we have our first
animation group
00:09:50.796 --> 00:09:52.756 A:middle
and we're setting
properties for our first view.
00:09:52.756 --> 00:09:55.166 A:middle
And then the completion handler
00:09:55.166 --> 00:09:57.786 A:middle
of that animation group
contains another animation group
00:09:57.926 --> 00:09:59.666 A:middle
and we set properties
for our second view,
WEBVTT
X-TIMESTAMP-MAP=MPEGTS:181083,LOCAL:00:00:00.000
00:10:00.316 --> 00:10:02.406 A:middle
likewise the completion handler
00:10:02.406 --> 00:10:04.346 A:middle
for that group contains
another animation group
00:10:04.636 --> 00:10:06.766 A:middle
and we're just setting
properties for view three here
00:10:06.846 --> 00:10:10.166 A:middle
so you can see here's the 3rd
animation group encapsulated
00:10:10.166 --> 00:10:12.996 A:middle
within the second
animation group, encapsulated
00:10:13.166 --> 00:10:15.456 A:middle
within the 1st animation group.
00:10:16.436 --> 00:10:18.986 A:middle
So I'm going to go ahead
and show you a demo
00:10:18.986 --> 00:10:23.966 A:middle