PrEV
Thoughts from a NeXTStep Guy on Cocoa Development

Grokking the CAMediaTiming protocol - Updated

Feb 12, 2008 by Bill Dudney

On of the topics in the chapter I just finished was on the media timing protocol. While the class doc's and the guide have a lot of good info in them I found them lacking in detail. So I decided to write myself an application that would allow me to twist all the knobs and flip all the switches so that I could make sure that my assumptions about how all that stuff worked was really how it worked.

I found a few surprises and spent quite a bit of time digging into stuff to make sure I really understood it before writing about it. And this sample app was really helpful in that regard. However it is way to big to put into the book and rather than keep if to myself I figured I'd share it. You can grab the code here and follow along with the rest of the discussion.

Here is a screen shot of the app in action.

Screen Shot

By default the mode is set to 'Forwards', makes sure you play with the other modes. A quick note on 'backwards', it is not obvious what the 'backwards' mode means in any of the examples I could come up with in this app. The best example I know of when 'backwards' is useful is when you have timeOffset happening on a fade in (i.e. when you set hidden=NO), you don't want the layer to appear until the timeOffset says so, if you set the fill mode to backwards then it will 'backfill' from when the animation starts back to the 'beginning' of time for that animation so the layer won't appear, disappear and then animate.

The 'Move' checkbox specifies that the layer should actually be moved instead of just having an animation applied. The 'Recenter' button places layer back in the center. The rest of the buttons are hopefully self explanatory.

The app is garbage collected I switched at the end so there might be some stray retain/release's in there.

Hope you find this helpful. It really helped me get my head wrapped around all the details of how this stuff fits together. The stuff I put in the book is more focused and has much smaller examples. So if you would learn better that way feel free to buy a copy of the book :)

Update:So if you have already downloaded the project (before 2:30 PM MST) you should grab it again, there is are a couple of missing retains (and a lack of xcode-fu on my part WRT GC settings) that was crashing (thanks Scott for letting me know). I've uploaded a new copy with the retain and I turned off GC.



Comments:

Thank you for the example. To get the application running under Xcode 3.2.5 you need to change the @synthesize statements in TimingView and TimingController as follows:

// TimingController.m
@synthesize timingView, layerFillMode;
@dynamic layerSpeed, layerRepeatCount, layerAutoreverse, layerDuration, layerOffset, layerBeginTime, moveLayer;

// TimingView.m
@synthesize beachLayer, layerBeginTime, moveLayer;
@dynamic layerSpeed, layerRepeatCount, layerFillMode, layerAutoreverse, layerDuration, layerOffset;

Posted by Tobias on September 02, 2011 at 02:09 PM MDT #

Post a Comment:
  • HTML Syntax: Allowed