I need to make an image move around (smoothly) when a button is tapped. How do I do this? Also, when a button is pressed, how do I change an the image, for a fixed amount of time, (say 5 seconds) then it changes back automatically.
Thanks, any code snippets or comprehensive tutorials will be appreciated.
I need to make an image move around (smoothly) when a button is tapped. How do I do this? Also, when a button is pressed, how do I change an the image, for a fixed amount of time, (say 5 seconds) then it changes back automatically.
Thanks, any code snippets or comprehensive tutorials will be appreciated.
Nathan
-I am using Xcode 4
You could put this in a method and call it when the button is tapped:
I am getting errors about bike.image such as "Property 'image' not found on object of type 'UIButton*'" and "Request for Member 'image' in something not a structure or union".
I tried deleting those lines of code (
Code:
bike.image = [UIImage imageNamed:@"bike.png"];
and
bike.image = [UIImage imageNamed:@"bike.png"];
) just to see what would happen, and the image then moved, but did not move back, as the application crashed and pointed me to:
I am getting errors about bike.image such as "Property 'image' not found on object of type 'UIButton*'" and "Request for Member 'image' in something not a structure or union".
I tried deleting those lines of code (
Code:
bike.image = [UIImage imageNamed:@"bike.png"];
and
bike.image = [UIImage imageNamed:@"bike.png"];
) just to see what would happen, and the image then moved, but did not move back, as the application crashed and pointed me to:
Code:
[self moveBackAnimation];
Thanks so far!
I used [self moveBackAnimation] as an example. You could define a method named -(void)moveBackAnimation - which basically has animation code (like the code I pasted) to move the animation back to where you want it to go.
Also to set your button image you could do: [bike setImage:[UIImage imageNamed:@"bike.png"] forState:UIControlStateNormal];
I used [self moveBackAnimation] as an example. You could define a method named -(void)moveBackAnimation - which basically has animation code (like the code I pasted) to move the animation back to where you want it to go.
Also to set your button image you could do: [bike setImage:[UIImage imageNamed:@"bike.png"] forState:UIControlStateNormal];
Thanks for that! That seems to almost work.
I am now getting errors in my -(void) action. I am getting told: "UIView may not respond to '+animatewithduration:delayptions:animations:'" and " Method '+animatewithduration:delayptions:animations:' not found (return type defaults to id)"