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-16-2010, 08:12 AM   #1 (permalink)
Registered Member
 
haza100's Avatar
 
Join Date: Jul 2009
Location: England
Posts: 81
haza100 is on a distinguished road
Default Rotate a UIImageView

Hi,
I am trying to rotate a UIImageView constantly using this code i found, but it doesn't seem to work:
Code:
-(void) awakeFromNib {
	angle = 0;
}

- (IBAction) gotoGame {
	[MenuView removeFromSuperview];
	[self addSubview:GameView];
	rotationTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(rotationFunction:) userInfo:nil repeats:YES];
}

-(void)rotationFunction:(NSTimer *)rotationTimer{
	angle +=0.01;
	if (angle > 6.283) { 
		angle = 0;
	}
	CGAffineTransform transform=CGAffineTransformMakeRotation(angle);
		Laser.transform = transform;
}
The strange thing is that if "angle +=0.01" is changed to "angle +=1" it works, but it sucks because it is not a smooth animation.

Thanks!
Harry.
haza100 is offline   Reply With Quote
Old 08-16-2010, 10:18 AM   #2 (permalink)
Registered Member
 
haza100's Avatar
 
Join Date: Jul 2009
Location: England
Posts: 81
haza100 is on a distinguished road
Default

Any help on getting the animation to run smoothly?
Thanks!
Harry.
haza100 is offline   Reply With Quote
Old 08-16-2010, 11:15 AM   #3 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Hi Harry.

If this is a continuous rotation, you might want to use CAnimation. If not, then there is no other way except to make the interval smaller. (0.01, 0.025, etc) Test in actual device to be sure.

Btw,
Code:
rotationTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(rotationFunction:) userInfo:nil repeats:YES];
the above line indicates userInfo as nil. so you don't really need that parameter of rotationTimer in the method.
Code:
-(void)rotationFunction:(NSTimer *)rotationTimer{
Just plain
Code:
-(void)rotationFunction {
will work fine. remember to remove the : in @selector() above.
rocotilos is offline   Reply With Quote
Old 08-16-2010, 03:45 PM   #4 (permalink)
Registered Member
 
haza100's Avatar
 
Join Date: Jul 2009
Location: England
Posts: 81
haza100 is on a distinguished road
Default

Hi,

Thanks for replying, I have tested it on a ipod touch and it still doesn't work, if i add anything less that 1 to the int "angle" it doesn't work :/

Thanks
Harry.
haza100 is offline   Reply With Quote
Old 08-16-2010, 03:47 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default

You can't add non-integers to an int variable It'll just chop off the decimal and add that, which means if you add 0.01 to an int it'll chop off the .01 and just add 0 (i.e. do nothing).

Change "angle" to a float type (which allows decimals) and it'll work.
SoulRed12 is offline   Reply With Quote
Old 08-16-2010, 03:53 PM   #6 (permalink)
Registered Member
 
haza100's Avatar
 
Join Date: Jul 2009
Location: England
Posts: 81
haza100 is on a distinguished road
Default

Thanks so much, ha, i reallllly suck for missing that. thanks for the help
haza100 is offline   Reply With Quote
Old 08-16-2010, 04:09 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 16
jjardim is on a distinguished road
Default Mshelper class

Quote:
Originally Posted by haza100 View Post
Thanks so much, ha, i reallllly suck for missing that. thanks for the help
I created a helper class last week and open sourced it. Search for mshelper on github. I have image rotation, scale, zoom, play sound etc.

On my website you can see videos of my apps and the movement/ rotation is all done with the methods in the class. Take a look at App Layout video, that's how i do all the animation
JSquared
MacSpots - software written by jay
jjardim is offline   Reply With Quote
Old 08-16-2010, 10:47 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 386
SoulRed12 is on a distinguished road
Default

Quote:
Originally Posted by haza100 View Post
Thanks so much, ha, i reallllly suck for missing that. thanks for the help
Nah, I've done that a dozen times myself. Glad it worked out for you
SoulRed12 is offline   Reply With Quote
Reply

Bookmarks

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: 355
4 members and 351 guests
givensur, linkmx, Newbie123, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
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:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0