views:

3608

answers:

4

I'm trying to make a Card class that duplicates the behavior of Dashboard widgets in that you can put controls or images or whatever on two sides of the card and flip between them.

Layer backed views have a transform property, but altering that doesn't do what I would expect it to do (rotating the layer around the y axis folds it off to the left side).

I was pointed to some undocumented features and an .h file named cgsprivate.h, but I'm wondering if there is an official way to do this? This software would have to be shipped and I'd hate to see it fail later because the Apple guys pull it in 10.6.

Anyone have any idea how to do this? It's so weird to me that a simple widget thing would be so hard to do in Core Animation.

Thanks in advance!

EDIT: I can accomplish this behavior with images that are on layers, but I don't know how to get more advanced controls/views/whatever on the layers. The card example uses images.

+2  A: 

It's overkill for your purposes (as it contains a largely-complete board and card game reference app), but check out this sample from ADC. The card games included with it do that flip effect quite nicely.

John Rudy
The cards in this sample are layers that have images supplied as their contents. I need to put controls (buttons, text fields, views) on the layers and I can't seem to find a nice way to do that.
Terrenius
Much rougher indeed ...
John Rudy
+1  A: 
e.James
Yeah. That's exactly the solution I was trying to avoid, or at least, avoid implementing it myself. I suspect that this is exactly what the Dashboard Widgets do as you can see it freeze and update.I was just hoping there was an established method to this.Thanks for the NSView methods!
Terrenius
+4  A: 

Mike Lee has an implementation of the flip effect for which he has released some sample code. It appears that he grabs the layers for the "background" and "foreground" views to be swapped, uses a CATransform3D to rotate the two views in the animation, and then swaps the views once the animation has completed.

By using the layers from the views, you avoid needing to cache into a bitmap, since that's what the layers are doing anyways. In any case, his view controller looks to be a good drop-in solution for what you want.

Brad Larson
Excellent! That's much better than caching the bitmap out.Getting there...
Terrenius
Yeah. That does it. Thanks a ton!
Terrenius
A: 

http://www.brockerhoff.net/src/index.html (the Flipr item). Not CoreAnimation, but a good starting point.