2009-11-10 104 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