gpt4 book ai didi

ios - 为什么我的计时器每隔几毫秒消失一次?

转载 作者:行者123 更新时间:2023-12-01 18:56:58 31 4
gpt4 key购买 nike

您好,我的计时器有问题,我不明白问题出在哪里,问题出在每英里或几秒钟,我的计时器消失了,出现了,我不明白为什么:

 - (void)viewDidLoad {
[super viewDidLoad];

self.BtnA.transform = CGAffineTransformMakeRotation( M_PI );
_timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(substractTime) userInfo:nil repeats:YES];
[self reset:nil];
}

- (IBAction)touchBtnA:(id)sender {
if (enabledA) {
[self.BtnA setEnabled:NO];
[self.BtnB setEnabled:YES];
enabledA = NO;
enabledB = YES;
[self.BtnA setAlpha:0.33];
[self.BtnB setAlpha:1.0];
} else {
[self.BtnA setEnabled:YES];
[self.BtnB setEnabled:NO];
enabledA = YES;
enabledB = NO;
[self.BtnB setAlpha:0.33];
[self.BtnA setAlpha:1.0];
}
}

- (IBAction)touchBtnB:(id)sender {
if (enabledB) {
[self.BtnB setEnabled:NO];
[self.BtnA setEnabled:YES];
enabledB = NO;
enabledA = YES;
[self.BtnB setAlpha:0.33];
[self.BtnA setAlpha:1.0];

} else {
[self.BtnB setEnabled:YES];
[self.BtnA setEnabled:NO];
enabledB = YES;
enabledA = NO;
[self.BtnA setAlpha:0.33];
[self.BtnB setAlpha:1.0];
}
}

- (void)substractTime {
if (enabledA) {
_remainingTimeA--;
if (_remainingTimeA == 0)
{
[self pause:nil];
[self.BtnA setEnabled:NO];
}
[self updateTime:A];
}

if (enabledB) {
_remainingTimeB--;
if (_remainingTimeB == 0)
{
[self pause:nil];
[self.BtnB setEnabled:NO];
}
[self updateTime:B];
}
}

- (void)updateTime: (TimerType)type {
NSInteger time = type == A ? _remainingTimeA : _remainingTimeB;
NSInteger minutes = time / 600;
NSInteger seconds = (time/10) % 60;
NSInteger milliseconds = time % 10;
if (type == A)
{
[self.BtnA setTitle:[NSString stringWithFormat:@"%02d:%02d:%01d",minutes, seconds, milliseconds] forState:UIControlStateNormal];
}
else
{
[self.BtnB setTitle:[NSString stringWithFormat:@"%02d:%02d:%01d",minutes, seconds, milliseconds] forState:UIControlStateNormal];

}
}

- (IBAction)pause:(id)sender {
enabledA = enabledB = NO;

}
- (IBAction)reset:(id)sender {
enabledA = enabledB = NO;
[self.BtnA setEnabled:YES];
[self.BtnB setEnabled:YES];
_remainingTimeA = _remainingTimeB = 6000;
[self updateTime:A];
[self updateTime:B];
[self.BtnA setAlpha:1.0];
[self.BtnB setAlpha:1.0];

}

感谢所有人的功能帮助。

最佳答案

您应该知道,NSTimer不会授予您调用选择器的重复间隔(在您的情况下为1.1)的绝对准确性。换句话说,您应该计算当前选择器调用与先前选择器调用之间的差,这将是精确的间隔

关于ios - 为什么我的计时器每隔几毫秒消失一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26179943/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com