domlao
domlao

Reputation: 16029

animate UIImageView with flip animation

I'm a noob in objective-c and cocoa, and I would like to implement a simple animation of UIImageView with flipping animation. But I'm having a hard time doing it. Below are my snippets:

UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,33,33)];
UIImageView *img1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:IMG1]];
UIImageView *img2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:IMG2]];                              
[containerView addSubview:img1];
[containerView addSubview:img2];
[self.view addSubview:containerView];

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[containerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];

Thanks.

Upvotes: 3

Views: 1992

Answers (1)

Jonathan Sterling
Jonathan Sterling

Reputation: 18385

You refer to an object called view which is never declared. I think you need to change your second-to-last line to

[containerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

See if that helps.

Upvotes: 1

Related Questions