2

I'm using two UITextView objects. Each UITextView represents the side of a single card in a flash card application. Just like when using regular flash cards, I want the user to have the ability to flip a card. I am asking how to flip between two UIView objects because UITextView are UIView subclasses so the same idea should work.

The animation I am looking for looks like this.

The only problem with the above example is that it utilizes two UIViewController objects and UITextView is not a subclass of UIViewController so the same principle does not apply.

Any ideas on how to do the flip animation?

jonsca
  • 10,218
  • 26
  • 54
  • 62
Mickster37
  • 155
  • 2
  • 10

3 Answers3

4

You can use the UIView class method +transitionFromView:toView:duration:options:completion: to accomplish this. Both your text views need to be descendants of a common superview. Use the option UIViewAnimationOptionTransitionFlipFromLeft (or ...FromRight) to get a horizontal flip.

Tim
  • 59,527
  • 19
  • 156
  • 165
  • This flips the whole screen, not just the UITextView. Besides that, it works. – Mickster37 Nov 09 '12 at 21:35
  • 3
    If your UITextViews' common superview is the main view for the current screen, then yes, it'll flip the whole screen. The common superview is what does the flip; you can avoid flipping the entire screen by introducing another view as the parent of both text views and a child of your root view. – Tim Nov 09 '12 at 22:10
0

Looks like your question has been answered already here, just tweak the transform to make it a horizontal instead of vertical flip:

- (void)horizontalFlip {
    [UIView animateWithDuration:someDuration animations:^{
        yourView.layer.transform = CATransform3DMakeRotation(M_PI, 0.0, 1.0, 0.0);
    } completion:^(BOOL finished){
        // code to be executed when flip is completed
    }];
}

As explained in that linked question, you can further modify this to do half the flip by using M_PI_2, then in the completion block of the first animation swap out the UITextViews and start a new animation to finish the flip.

Don't forget to #import math.h and #import <QuartzCore/Quartz.h> at the top of your file!

Community
  • 1
  • 1
smileyborg
  • 30,197
  • 11
  • 60
  • 73
0

you can first hide the one UITextView and Show the another UITextView. To flip it, you can hide the displayed UITextView and show the hidden UITextView. You can also use animations explained here for it to create a flip effect.

Community
  • 1
  • 1
note-knotz
  • 173
  • 2
  • 8