I have a problem. Theres my View, with 2 UIButtons and an UIImageView. When a Button is pressed down then i want to move the Image, when it isn't touched down, I want to stop the UIImage. But I have no idea how this works. Maybe you can help me. Here's my Code:
- (void)viewDidLoad
{
currentPositionx = 150.0;
currentPositiony = 150.0;
currentSizex = 147.0;
currentSizey = 146.0;
currentSpeed = 0.70;
contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[contentView setImage:[UIImage imageNamed:@"BlackScreen.png"]];
[contentView setUserInteractionEnabled:YES];
[contentView setMultipleTouchEnabled:YES];
self.view = contentView;
[contentView release];
// create the view that will execute our animation
currentPlayer = [[UIImageView alloc] initWithFrame:CGRectMake(currentPositionx, currentPositiony, currentSizex, currentSizey)];
// load all the frames of our animation
currentPlayer.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"RunnerRED_0.png"],
Nil];
currentPlayer.animationDuration = currentSpeed;
currentPlayer.animationRepeatCount = 0;
[currentPlayer startAnimating];
[self.view addSubview:currentPlayer];
[currentPlayer release];
UIButton *GoLeftButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(20, 263, 64, 64)];
[GoLeftButton addTarget:self action:@selector(GoLeft:) forControlEvents:UIControlEventTouchUpInside];
[GoLeftButton setBackgroundImage:[UIImage imageNamed:@"Arrow Left RED.png"] forState:UIControlStateNormal];
[self.view addSubview:GoLeftButton];
UIButton *GoRightButton = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(100, 263, 64, 64)];
[GoRightButton addTarget:self action:@selector(GoRight:) forControlEvents:UIControlEventTouchUpInside];
[GoRightButton setBackgroundImage:[UIImage imageNamed:@"Arrow Right RED.png"] forState:UIControlStateNormal];
[self.view addSubview:GoRightButton];
}
-(void)GoLeft:(id)sender
{
CGRect frame = currentPlayer.frame;
frame.origin.x = frame.origin.x - 10;
currentPlayer.frame = frame;
currentPlayer.transform = CGAffineTransformIdentity;
currentPlayer.transform = CGAffineTransformMakeScale(-1.0, 1.0);
}
-(void)GoRight:(id)sender
{
CGRect frame = currentPlayer.frame;
frame.origin.x = frame.origin.x + 10;
currentPlayer.frame = frame;
currentPlayer.transform = CGAffineTransformIdentity;
currentPlayer.transform = CGAffineTransformMakeScale(1.0, 1.0);
}
@end
I hope you can help me
thx