Mickster37
Mickster37

Reputation: 155

How can I flip between two UIView?

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?

Upvotes: 2

Views: 920

Answers (3)

note-knotz
note-knotz

Reputation: 173

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.

Upvotes: 0

Tim
Tim

Reputation: 60130

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.

Upvotes: 4

smileyborg
smileyborg

Reputation: 30469

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!

Upvotes: 0

Related Questions