2014-03-06 53 views
6

我有一個圖像。我想旋轉就像一枚硬幣旋轉在表面上。我嘗試了旋轉變換,但它不像那樣旋轉。如何實現這樣的動畫?像硬幣一樣旋轉圖像

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

ND:

#import "LoginViewController.h" 

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

應用3D旋轉 –

+1

嘗試是這樣的:http://stackoverflow.com/questions/6531332/how-to-rotate-an-uiimageview-with-catransform3drotate-make-an -effect-like-door-o – Radu

+1

使用'CATransform3DRotate' –

回答

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

你介意分享一些代碼如何實現? – Elhoej

+1

@Elhoej檢查我編輯的答案......如果它可以幫助你upvote :) :) – vivek

+0

使用這種方法,我該如何設置動畫旋轉?你能告訴我完整的代碼示例嗎?對不起,無法使用它:( – Elhoej

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

+0

@reacon真棒:) – Rushabh

+0

不工作...... – vivek

+0

爲什麼它不工作?你有沒有導入Quartzcore框架? – GenieWanted