Graphics Reference
In-Depth Information
Listing 7-6 adds code to instantiate a CATextLayer as a sublayer of the QTMovieLayer . The
text is aligned at the center of the layer frame using
setAlignmentMode:kCAAlignmentCenter . Now when the movie plays, you will see the text
“Do Not Try This at Home!” displayed at the top of the frame.
Figure 7-4 shows what the basic overlay looks like. Notice that the text layer's frame is set
to the same bounds as the window's content view. As such, the text displays at the top of
the image.
FIGURE 7-4
Displaying “Do Not Try This at Home” Overlay
Overlaying a Time Code
One common requirement when building a movie player is the capability to see a time
code for the movie as it is playing. Once again, the code to overlay a time stamp is fairly
trivial when using Core Animation layers. To accomplish this, the first step is to create a
CATextLayer as in the previous example, and then update the string field of the
CATextLayer using -setString on a periodic basis.
In Listing 7-5, we implemented a timer for updating the slider position as the movie
played. We can use this same timer to update the text overlay to use the current time of
the movie as represented by the value we get back from a call to the movie object's
currentTime .
Search WWH ::




Custom Search