Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
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 (
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 (
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:
[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:delay:options:animations:'" and " Method '+animatewithduration:delay:options:animations:' not found (return type defaults to id)"
Replies
http://www.mormon.org
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeAny suggestions, also, what about changing the image?
Thanks again.
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome.png or .jpeg or whatever you are using
http://www.mormon.org
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome-(IBAction)pushbikemove {
CGRect theMoveToPosition = CGRectMake(50, 50, bike.frame.size.width, bike.frame.size.height);
[UIView animateWithDuration:5 delay:0 options:UIViewAnimationCurveEaseInOut
animations:^ {
bike.image = [UIImage imageNamed:@\"bike.png\"];
bike.frame = theMoveToPosition;
}completion:^(BOOL finished) {
if (finished) {
bike.image = [UIImage imageNamed:@\"bike.png\"];
[self moveBackAnimation];
}
}];
}
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 (
) just to see what would happen, and the image then moved, but did not move back, as the application crashed and pointed me to:
Thanks so far!
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeAlso to set your button image you could do: [bike setImage:[UIImage imageNamed:@"bike.png"] forState:UIControlStateNormal];
http://www.mormon.org
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like AwesomeI am now getting errors in my -(void) action. I am getting told: "UIView may not respond to '+animatewithduration:delay:options:animations:'" and " Method '+animatewithduration:delay:options:animations:' not found (return type defaults to id)"
My overall code is:
-(IBAction)pushbikemove {
CGRect theMoveToPosition = CGRectMake(50, 50, bike.frame.size.width, bike.frame.size.height);
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationCurveEaseInOut
animations:^ {
bike.frame = theMoveToPosition;
}completion:^(BOOL finished) {
if (finished) {
[self pushbikemoveback];
}
}];
}
-(void)pushbikemoveback {
CGRect theMoveToPosition = CGRectMake(6, 39, bike.frame.size.width, bike.frame.size.height);
[UIView animateWithDuration:1 delay:0 options:UIViewAnimationCurveEaseInOut
animations:^ {
bike.frame = theMoveToPosition;
}
];
- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 · Off Topic Insightful Disagree Dislike Like Awesome