像硬币一样旋转图像

时间:2014-03-06 08:55:25

标签: ios cocoa-touch animation

我有一张图片。我想旋转它像硬币旋转表面。我试过旋转变换,但它没有像那样旋转。如何实现这样的动画?

enter image description here

代码:

- (void)viewDidLoad {
[super viewDidLoad];
[self.view setUserInteractionEnabled:YES];
lbl_facebook.font=[UIFont fontWithName:GZFont size:12.0f];
txtPassword.font=[UIFont fontWithName:GZFont size:15.0f];
txtUsername.font=[UIFont fontWithName:GZFont size:15.0f];

CATransition* transition = [CATransition animation];
transition.startProgress = 0;
transition.endProgress = 1.0;
transition.type = @"flip";
transition.subtype = @"fromRight";
transition.duration = 0.3;
transition.repeatCount = 2;
[_Image.layer addAnimation:transition forKey:@"transition"];
}

第二

#import "LoginViewController.h"

#import "RegistrationViewController.h"
#import "ForgetPasswordViewController.h"
#import "ForgetPasswordController.h"
#import "SearchServiceProviderViewController.h"
#import <QuartzCore/QuartzCore.h>

2 个答案:

答案 0 :(得分:19)

这将是一个很好的,类似硬币的翻转:

CATransition* transition = [CATransition animation];
transition.startProgress = 0;
transition.endProgress = 1.0;
transition.type = @"flip";
transition.subtype = @"fromRight";
transition.duration = 0.3;
transition.repeatCount = 2;

将过渡动画添加到视图层:

[_yourView.layer addAnimation:transition forKey:@"transition"];

看到它的实际效果:

enter image description here

答案 1 :(得分:2)

像这样旋转的一个好方法就是采用不同角度的不同硬币图像,如旋转图像。然后将所有这些图像添加到数组中并使用该数组启动图像动画。这将为您提供更好的效果......像视频框架这样的简单过程。

像:

NSArray *animationArray = [NSArray arrayWithObjects:
                          [UIImage imageNamed:@"images.jpg"],
                          [UIImage imageNamed:@"images1.jpg"],
                          [UIImage imageNamed:@"images5.jpg"],
                          [UIImage imageNamed:@"index3.jpg"],
                          nil];
UIImageView *animationView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,320, 460)];
animationView.backgroundColor      = [UIColor purpleColor];
animationView.animationImages      = animationArray;
animationView.animationDuration    = 1.5;
animationView.animationRepeatCount = 0;
[animationView startAnimating];