tags:

views:

372

answers:

2

how to flip UIImageView

+1  A: 

You should be able to flip the view vertically with:

imageView.transform = CGAffineTransformMake(
    1, 0, 0, -1, 0, imageView.bounds.size.height
);
teabot
that flips it diagonal
Sney
+2  A: 

create two UIImageView frontImageView & backImageView

create one UIView containerView to contain UIImageView

Show frontImageView in the beginning.

after flip, show backImageView

code:

// before flip
frontImageView = [[UIImageView alloc] initWithImage:[UIImage 
        imageNamed:@"test.png"]];

containerView = [[UIView alloc] initWithFrame:frontImageView.bounds];
containerView.center = CGPointMake(200,200);

[self.view addSubview:containerView];
[containerView addSubview:frontImageView];

-(IBAction)flipButtonClicked:(id)sender
{
     backImageView = [[UIImageView alloc] initWithImage:[UIImage 
          imageNamed:@"cardback.png"]];
     backImageView.center = frontImageView.center;
     [UIView beginAnimations:nil context:NULL];
     [UIView setAnimationDuration:1.0];
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft 
                            forView:containerView 
                              cache:YES];
     [frontImageView removeFromSuperview];
     [containerView addSubview:backImageView];
     [UIView commitAnimations];
}
deeplovepan