Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spinning an image around like a coin

I have one image. I want to spin it like a coin spin on surface. I tried rotation transform but it does not spin like that. How to achieve such an animation?

enter image description here

code:

- (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>
like image 848
vivek bhoraniya Avatar asked Mar 06 '14 08:03

vivek bhoraniya


People also ask

How do you rotate animation in After Effects?

To access the expression editor in After Effects click the triangular menu button on the left side of your layer. Then open the transform effects, and there we will find our rotation property. You can also select your layer and press 'R' on your keyboard if you like to use handy keyboard shortcuts.


2 Answers

This will make a nice, coin-like flip:

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

And add the transition animation to the layer of your view:

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

See it in action:

enter image description here

like image 153
Rafa de King Avatar answered Sep 21 '22 17:09

Rafa de King


One good trick to spin like this is that take different images of coin with different angle like spinning image. And then add all those images to array and start animation of images with that array..it will give you much better effect...Simple process like video framing.

Like:

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]; 
like image 24
vivek bhoraniya Avatar answered Sep 23 '22 17:09

vivek bhoraniya