views:

325

answers:

1

I have a card (a flashcard you could say)

What I can do:

On fingersweeping over the flashcard the card gets turned. It's happening by detecting touchesBegan and touchesMoved and then I do stuff like

[UIView beginAnimations:@"View Flip" context:nil]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (left) {
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.flashCardView cache:YES];
}else{
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.flashCardView cache:YES];
}

What I can't do (but want to):

I want to somehow drag the flip. Imagine this, you have a flashcard and you think you know the answer, you start flipping the card around because you want to see if you are correct, but then... no stop... you hesitate, turn back the card to the way it was, rethink, get the real answer and then finally flip to see that you were right to hesitate.

Now I only have: once you start flipping, you can't stop it.

So do you have any hints on how to do this ? something to read ? I'm still at the beginning of understanding cocoa and iPhone development

EDIT I'm more experienced now, but I still haven't done such custom animations, maybe someone can give me a lift ?

+1  A: 

You cannot achieve what you're trying to do with the preset UIView animations because the animation is one-time and cannot be intercepted. You can use OpenGL for true 3D transformations (what you need is rotation about an axis), or for a speedier implementation try CALayer transforms as drawnonward suggested.

Here is an example of the interactive 3D page flip implemented in OpenGL. It uses private APIs, but it might help you understand how to respond to user input and apply transforms appropriately.

hyn
For rotation about an axis, you can use the CALayer transform property. Unlike the UIView transform, CALayer allows 3D transforms.
drawnonward
Hm, I didn't know that about CALayer. That is probably a better approach, OpenGL may be overkill for a simple flip animation.
hyn