2009-11-10 206 views
3

我是objective-c和可可中的noob,我想用翻转动画实现UIImageView的简单动画。但我很难做到这一点。以下是我的片段:使用翻转动画动画UIImageView

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]; 

谢谢。

+0

嗨!任何解决方案? – Frade 2012-09-25 16:47:23

回答

1

您指的是从未声明过的名为view的对象。我认为你需要你的第二个到最后一行改为

[containerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; 

看看是否有帮助。

+0

oopss,对不起,它是一个mistypo。谢谢 – domlao 2009-11-10 06:06:13

+0

注意我上面的评论并不意味着我的问题已解决。 – domlao 2009-11-10 07:33:05