Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mandude

macrumors member
Original poster
Nov 19, 2009
64
0
please help someone. i have a simple UIButton that was doing its job fine until i animated it to go from left to right on the screen. when i try to press the button while it's moving nothing happens. : [



h. file

Code:
@interface.... {
UIButton *button;
}
@property (nonatomic, retain) IBOutlet UIButton *button;
-(IBAction)action;
@end

m. file

Code:
// the button is placed in interface builder at an x coordinate of  -50.

-(void)viewDidLoad {
[UIView beginAnimations:@"ButtonMove" context:nil];
	[UIView setAnimationDuration:6.0];
	[UIView setAnimationRepeatCount:10];
	CGPoint center = Button.center;
	if (center.x < 10) {
		center.x += 540.0f;
	}
	stickButton.center = center;
	[UIView commitAnimations];
 
I've never tried to click a moving button. That might be undefined behavior.

Is there a reason it has to be a button (as opposed to a view?)
 
well actually i want the "button" to be a stick figure walking along the screen left to right. and when the user taps the stick figure (button) a label appears. so #1 how in the world can i make it look like a stick figure is walking and able to make the stick figure able to be tapped like a button and have an IBAction connected to it. please don't be too harsh i'm no expert (as you can see)
 
well actually i want the "button" to be a stick figure walking along the screen left to right. and when the user taps the stick figure (button) a label appears. so #1 how in the world can i make it look like a stick figure is walking and able to make the stick figure able to be tapped like a button and have an IBAction connected to it. please don't be too harsh i'm no expert (as you can see)

Ah, I see. I would tend to do this by creating a custom view (ManView) and implement a custom drawRect function to draw the man. You can also implement touch event handlers that call back to a controller to display a message (the event handler could check if the touch coordinates match the current position of the man or not).
 
ahh i sort of understand you're logic... make a new view and have that keep drawing up different rects of him moving... and everytime i touch i can check to see if the coordinates of my touch match the coordinates of the man... then BAM yet i dont really know how to get that idea into code... you've given much help and i dont want to ask u how to do this but im not sure how the code would work for this : /
 
ahh i sort of understand you're logic... make a new view and have that keep drawing up different rects of him moving... and everytime i touch i can check to see if the coordinates of my touch match the coordinates of the man... then BAM yet i dont really know how to get that idea into code... you've given much help and i dont want to ask u how to do this but im not sure how the code would work for this : /

Well, I'd start by, in xcode, creating a new file, derived from UIView. If you are drawing the man by swapping bitmaps, have your new class have an array of CGImageRefs (you can get them from UIImages by calling the .CGImage function). Maybe have an integer called currentFrame or something, and a function like -(void)incrementFrame {currentFrame++;if (currentFrame>maxFrame) currentFrame=0;}

Then, in your drawRect, use the coregraphics functions to draw the cgimage corresponding to currentFrame on your cgcontext.

In your main controller class you can have an nstimer that calls incrementFrame at regular intervals. You can either make your view small and use the nstimer to move it, or make the view big and use the nstimer to set the x,y of the cgimage.
 
I'll be sure to do so. Thanks a bunch this forum could use more nice dudeS like u. I'll PM u if... When something goes wrong lol
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.