簡體   English   中英

使用翻轉動畫動畫UIImageView

[英]animate UIImageView with flip animation

我是Objective-c和cocoa中的菜鳥,我想用翻轉動畫實現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];

謝謝。

您引用一個名為view的對象,該對象從未聲明。 我認為你需要改變你的倒數第二行

[containerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

看看是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM