如何在iPhone应用中实现图像翻转动画

5
我该如何实现图片向右翻转的动画效果呢?下面是给出的代码,请帮忙。
imageview.animationImages=[NSArray arrayWithObjects:  
   [UIImage imageNamed:@"image1.png"],
   [UIImage imageNamed:@"imag2.png"],
   [UIImage imageNamed:@"imag3.png"],
   [UIImage imageNamed:@"imag4.png"],
   [UIImage imageNamed:@"imag5.png"], 
   [UIImage imageNamed:@"imag6.png"],
   [UIImage imageNamed:@"imag7.png"], nil];

imageview.animationDuration=15.0;
imageview.animationRepeatCount=0;
[imageview startAnimating];

1
你的做法有什么问题? - Manish Agrawal
@Will:这只是一个简单的动画。我如何逐个向右翻转图像? - Nila
2个回答

9

用于垂直翻转

[UIView animateWithDuration:1.0 animations:^{
    yourView.layer.transform = CATransform3DMakeRotation(M_PI,1.0,0.0,0.0);
} completion:^(BOOL finished){
    // code to be executed when flip is completed
}];

水平翻转:

[UIView animateWithDuration:1.0 animations:^{
    yourView.layer.transform = CATransform3DMakeRotation(M_PI,0.0,1.0,0.0);
} completion:^(BOOL finished){
    // code to be executed when flip is completed
}];

不要忘记将QuartzCore框架添加到项目中并导入。
#import <QuartzCore/QuartzCore.h>

我尝试了这段代码,但是出现了错误。这是因为iOS 4.0吗? - Nila
这应该适用于iOS 4.0或更高版本,您具体遇到了什么错误? - Asif Mujteba
未定义符号,适用于i386架构: "CATransform3DMakeRotation",引用自: homeViewController.o中的__-[homeViewController viewDidLoad]_block_invoke_1 ld:找不到符号(s)适用于i386架构 collect2:ld返回1个退出状态 - Nila
在编程中,如果要包含QuartzCore头文件,您还需要右键单击“框架”,选择“添加现有框架”,然后添加“QuartzCore.framework”。 - Asif Mujteba

2
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:imageview cache:NO];
[UIView commitAnimations];

我认为这段代码可能会对你有所帮助。

@nila,图片应该如何翻转,是像并排滚动(垂直滚动)还是像视图控制器翻转? - alex
请查看此链接,我认为它适合您的需求:http://czetsuya-tech.blogspot.in/2011/01/create-image-slide-show-in-iphone-using.html - alex

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接