Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-10-2010, 10:12 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Age: 29
Posts: 9
Smikey is on a distinguished road
Default Animating a UIImageView Rotation - Swingometer

Hi there. I've spent a few hours reading up about this on various forums and am just a little unclear on a couple of things. I'm basically trying to implement a golf-game style swingometer, where the user holds a button to start a swing, releases at the apex to determine power, at which point the 'swing' reverses direction, and the user taps again on the way down to set the accuracy.

Rather than having a bar that fills up, I would like to use a pendulum that swings from left to right. The pendulum leaves a mark where it is first tapped (power) and another mark where it is tapped for the second time (accuracy).

Just to make the pendulum move, i.e. rotate the view, I tried the following:

Code:
- (void)viewDidLoad {
    pendulum.image = [UIImage imageNamed:@"pendulum.png"];
    [self swingPendulum];
}

- (void) swingPendulum;
{
    CABasicAnimation *rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0]; ///* full rotation*/ * roation * duration ];
    rotationAnimation.duration = 2.0;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0; 
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

    [pendulum.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
This works fine so far, but I've also seen a different approach, as I've done below:

Code:
- (void)swingPendulum {
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:2];
	CGAffineTransform transform = CGAffineTransformMakeRotation(degreesToRadian(180));
	pendulum.transform = CGAffineTransformScale(transform, 1, 1);
	[UIView commitAnimations];
}
Could anyone tell me which approach is better and why?

My question really, is how best to approach the solution to this problem as a whole. Is a UIView rotation animation the best bet? I don't need to calculate accurately how far from the correct point the pendulum is stopped, simply if it's too strong, too weak or just right. I can presumably do this by just taking the angle it's at when the user hits the button. I.e. < 170 degrees = too weak, > 170 and < 190 = just right and > 190 = too strong. But then I need to extract the current image's transformation angle from somewhere... Is there an easy way to do this?

I hope this question isn't too vague. I've been messing around for so long on this my brain is a bit of a muddle, so I guess I'm wondering what the pros would do, before I commit several more hours wandering around in the dark.

Thanks for any help - very much appreciated

Michael

Last edited by Smikey; 08-10-2010 at 12:18 PM.
Smikey is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, cgaffinetransform, cgbasicanimation, rotation, uiview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 344
9 members and 335 guests
bignoggins, Chickenrig, firecall, iNet, linkmx, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,893
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:38 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0