添加分数后,UIButton不会随机生成?

时间:2023-02-10 21:07:54

I am having a problem with my coding on Xcode. I am making an app in which a target appears, then you have to tap it, but the time allowed between each tap shortens gradually.

我在Xcode上的编码有问题。我正在创建一个目标出现的应用程序,然后你必须点击它,但每次点击之间允许的时间逐渐缩短。

MY PROBLEM: whenever I try and make a UILabel update after a tap, the target goes back to it's original position on my view controller. I have all relevant code here:

我的问题:每当我尝试在点击后进行UILabel更新时,目标会回到它在我的视图控制器上的原始位置。我在这里有所有相关的代码:

-(IBAction)startButtonPressed:(id)sender {

    startButton.hidden = YES;
    Text.hidden = YES;

    targX = arc4random() %769;
    targY = arc4random() % 925;

    Target.center = CGPointMake(targX, targY);

    Target.hidden = NO;
}

-(IBAction)targetTapped:(id)sender {

    [Time invalidate];

    targX = arc4random() %769;
    targY = arc4random() % 925;

    [self scoreAdd:(id)sender];

    Target.center = CGPointMake(targX, targY);
    timeMax = 5 - (Score * 0.05);

    if (Score >= 90) {
        timeMax = 0.5;
    }

    Time = [NSTimer scheduledTimerWithTimeInterval:timeMax target:self selector:@selector(Lose:) userInfo:nil repeats:NO];

}

-(void)Lose:(id)sender {

    Target.hidden = YES;
    Text.hidden = NO;

}


-(void)scoreAdd:(id)sender{

    Score = Score + 1;
    scoreLabel.text = [NSString stringWithFormat:@"Score: %li", Score];

}

1 个解决方案

#1


print targX = arc4random() %769; targY = arc4random() % 925;

print targX = arc4random()%769; targY = arc4random()%925;

in both methods , check whether you are getting proper points. And check generated points lies with in device screen.

在这两种方法中,检查你是否得到了正确的分数。并检查生成的点位于设备屏幕中。

#1


print targX = arc4random() %769; targY = arc4random() % 925;

print targX = arc4random()%769; targY = arc4random()%925;

in both methods , check whether you are getting proper points. And check generated points lies with in device screen.

在这两种方法中,检查你是否得到了正确的分数。并检查生成的点位于设备屏幕中。