每次用户点击图片时,如何将标签重置为零? 我现有的方法不起作用。
以下是我认为您需要的代码:
int number = 0;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if ([self Intersecting:location :Ball]) {
number++;
[labelCurrentNumber setText:[NSString stringWithFormat:@"%d", number]];
}
}
-(IBAction)startMove {
buttonStart.hidden = YES;
Ball.hidden = NO;
labelEasy.hidden = YES;
buttonBack.hidden = YES;
Destination = CGPointMake(arc4random() % 320, arc4random() % 480);
xamt = ((Destination.x - Ball.center.x) / speed);
yamt = ((Destination.y - Ball.center.y) / speed);
mainTimer = [NSTimer scheduledTimerWithTimeInterval:(0.02) target:self selector:@selector(moveBall) userInfo:nil repeats: YES];
mainInt = 20.00;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
}
请帮帮我,谢谢你。
答案 0 :(得分:0)
只需为要更改为零的金额设置一个整数,并使标签显示为整数。然后你所要做的就是代码“当按下按钮时,将整数名称设置为0。
答案 1 :(得分:0)
您可能需要考虑UITapGestureRecognizer
,而不是侦听触摸事件和计算交集。只需将您的设置添加到零方法作为目标,然后将手势识别器添加到图像中。