当向左或向右触摸时,Xcode下降图像从顶部再次重新开始

时间:2014-12-20 03:35:32

标签: ios objective-c xcode image touchesbegan

代码运行时,图像将从屏幕顶部开始下降。我还有一个touchesBegan触摸屏左侧和屏幕右侧。但是,一旦代码运行且图像正在下降,当我触摸屏幕的左侧或右侧时,下降的图像将重新启动并再次从顶部开始。这仅适用于第一次LHS或RHS触摸。以下触摸不会重新开始下降的图像。

为什么会这样?如何修改代码?

我的代码如下:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.view];

//When left hand side of screen touched, image will be Left.png, if RHS touched, image will be right.png
if(point.x < 240){

    stillImage.image = [UIImage imageNamed:@"Left.png"];

}else{

    stillImage.image = [UIImage imageNamed:@"Right.png"];

}
}

-(void)movement{

fallingImg.center = CGPointMake(img.center.x, img.center.y - 3);

}

-(IBAction)start:(id)sender{

fallingmovement = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(movement) userInfo:nil repeats:YES];

}

0 个答案:

没有答案