Note: This method does not use Core Animation, but it's very simple and probably uses less resources First, make the UIImageView twice as tall, thereby making the center of rotation equal to the center of the image Then, define these in the @interface of the header file (of, say, your UIViewController): BOOL goingCW; // going clockwise = YES, going counterclockwise = NO CGFloat angle; // angle by which to change the image's rotation value Then put this in an init method that runs once: goingCW = YES; // change this to NO to make it start rotating CCW instead angle = 0; NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(update) userInfo:nil repeats:YES Then define update given that arrow is the UIImageView instance: (void)update { if (goingCW) { if (angle > M_PI / 4) goingCW = NO; // M_PI / 4 is equal to 45 degrees angle += M_PI / 60; // increase 60 to slow down the rotation, etc. } else { if (angle Transform = CGAffineTransformMakeRotation(angle); } This also assumes that you are starting in the facing-down position.
Note: This method does not use Core Animation, but it's very simple and probably uses less resources. First, make the UIImageView twice as tall, thereby making the center of rotation equal to the center of the image. Then, define these in the @interface of the header file (of, say, your UIViewController): BOOL goingCW; // going clockwise = YES, going counterclockwise = NO CGFloat angle; // angle by which to change the image's rotation value Then put this in an init method that runs once: goingCW = YES; // change this to NO to make it start rotating CCW instead angle = 0; NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(update) userInfo:nil repeats:YES; Then define update, given that arrow is the UIImageView instance: - (void)update { if (goingCW) { if (angle > M_PI / 4) goingCW = NO; // M_PI / 4 is equal to 45 degrees angle += M_PI / 60; // increase 60 to slow down the rotation, etc.} else { if (angle.
Thats okay, but a few things. With this method I cannot make a smooth transition at the end of the angle. I heared that animating with NSTimes is a "bad thing", but I don't know.
Your method is the best working atm. – choise Feb 8 '10 at 14:15 maybe try changing the timeInterval from 0.05 (which runs 20 times a second) to 0.01 (which runs 100 times a second) or some other interval. Let me know how that goes.
– Arseniy Banayev Feb 8 '10 at 21:03 actually I just realized what you may have meant. Was "a smooth transition at the end of the angle" supposed to mean a simulated gravity-type effect where a force is pulling down on the arrow and decreasing the angle change at the height of the rotation? If so, you can modify the existing code by making the incrementation of angle (i.e.
, the "-=" and "+=" code) a function of the current y offset of a certain point on the image. Maybe make another variable that counts up and then down every iteration of -(void)update, so that since – Arseniy Banayev Feb 9 '10 at 17:12 continued... the uiimageview does not move (i.e. , you cannot watch for the otherwise constant x or y positions), you can make the angle increment or decrement depend on that extra variable.
Does that solve your problem? – Arseniy Banayev Feb 9 '10 at 17:13.
It does almost exactly what you're trying to do, using Core Animation.
1 thanks, I looked into that, but this example is totally overloaded. I don't really find the essential part, with the plain animation. – choise Feb 8 '10 at 14:16 1 hahaha... this is typical of Apple.
Their documentation and examples are the finest crap one company can ever produce. Not even M$ in all their "crappyness" can produce docs like that. It is like someone trying to explain brain surgery using twitter with 140 chars or less ... "this function does this.", "to make this work, use this"... The code samples are worst than the docs.
They make a 10,000 lines code to explain how to vibrate the device, instead of creating a collection of snippets that one could understand. If it was not sites like SO and a couple of books we would be screwed. – Digital Robot Apr 12 '10 at 16:45.
Im trying to do an animation with an uiimageview. In this view is an image with an arrow, that I want to rotate about 45 degrees back and forward very smoothly like an pendular or an old clock. This is really a pain, add 45 degrees, then 45 degrees backward with "-45" doesn't work.
Im very new to core animation and don't know how to setup my code, to get my wanted animation. Can anybody help please?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.