fs_tigre
fs_tigre

Reputation: 10738

How to flip a view with a label on the front side and another label on the back side - see image

How can I flip a view with a label on the front side and another label on the back side when a button is clicked? Something that looks like the image below.

What would be the logic to create this effect? enter image description here

Thanks

EDIT:

Sorry about the confusion but please note that I'm just talking about a view not ViewControllers, this effect will happen within the same viewController. I have updated the image to reflect that the view I'm talking about is a subView inside the main view.

Upvotes: 0

Views: 228

Answers (3)

Sandeep Ahuja
Sandeep Ahuja

Reputation: 931

Call this method in your viewController, your viewController view flips and viewController life cycle method calls and simply change the image of UIImageView you want to display in -(void)viewdidload method.

    [UIView  beginAnimations: @"Showinfo"context: nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    UIView *parent = self.view.superview;
    [self.view removeFromSuperview];
    self.view = nil; // unloads the view
    [parent addSubview:self.view]; //reloads the view from the nib
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
    forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];

    Please vote up if you find it helping

Upvotes: 1

rdurand
rdurand

Reputation: 7410

What you can do is use two UIViews, one for the first side, one for the second side.

Show the first view, hide the second view, and set the second view's frame to have a width of 0.

Then, when your first view is visible, animate its frame to have a width equal to 0. Hide the first view, unhide the second view, and animate the second view's frame to the desired frame.

Edit : This does not appear to work well if you have labels in your views, as this is a 2D flip. Sorry about that. @Maverick's answer could work pretty well in your case.

Upvotes: 1

Maverick
Maverick

Reputation: 319

I too had something very similar situation, on click of a button on ViewController1 I have to move to another ViewController2. I used this code,

//code this in ViewController1
-(IBAction)flipView:(id)sender
{
    ViewController2 *view2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:1.0];
    [[self navigationController] pushViewController:view2 animated:YES];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO]; 
    [UIView commitAnimations];
    [view2 release];
}

//code this in ViewController2 on click of back button
-(IBAction)flipView:(id)sender
{
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:1.0];

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO]; 
    [[self navigationController] popViewControllerAnimated:YES];
    [UIView commitAnimations];  
}

But in this code I am using 2 classes, if it is fine to you, use this code. Hopes it solves your problem to some extent.

Upvotes: 2

Related Questions