gpt4 book ai didi

ios - 与 NSTimer 一起使用时,进度条显示滴答动画而不是平滑动画

转载 作者:行者123 更新时间:2023-11-29 02:58:27 26 4
gpt4 key购买 nike

我使用 NSTimer 和圆形进度条作为倒计时器,即 15 秒

它与以下代码一起工作,但我得到的是进度条的刻度动画而不是平滑的动画,如何使它平滑动画

- (void)viewDidLoad
{
[super viewDidLoad];
self.labeledLargeProgressView.roundedCorners = NO;
self.labeledLargeProgressView.trackTintColor =[UIColor colorWithRed:0.0f/255.0f green:173.0f/255.0f blue:255.0f/255.0f alpha:1.0f];
self.labeledLargeProgressView.progressTintColor =[UIColor colorWithRed:255.0f/255.0f green:96.0f/255.0f blue:88.0f/255.0f alpha:1.0f];
self.labeledLargeProgressView.thicknessRatio = 1.0f;
self.labeledLargeProgressView.clockwiseProgress = YES;
[self.view addSubview:self.labeledLargeProgressView];
seconds = 15.0;
[self startAnimation];
}

- (void)progressChange
{

CGFloat progress ;
DALabeledCircularProgressView *labeledProgressView = self.labeledLargeProgressView;
if(labeledProgressView.progress >=1.0f && [self.timer isValid]){
[self stopAnimation];
seconds = 15.0f;
}
else{
progress=labeledProgressView.progress + 0.06666667f;
[labeledProgressView setProgress:progress animated:YES];
seconds --;
labeledProgressView.progressLabel.text = [NSString stringWithFormat:@"%i", seconds];
}


}

- (void)startAnimation
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(progressChange)
userInfo:nil
repeats:YES];
self.continuousSwitch.on = YES;
}

- (void)stopAnimation
{
[self.timer invalidate];
self.timer = nil;
self.continuousSwitch.on = NO;
}

最佳答案

我发现的是一组 UIview 动画和进度 View 动画,它们工作得更好并且可以流畅地动画化进度 View 。如果你只是使用动画和 progressview 动画的组合,它会被直接触发而不考虑 UIview 动画计时器。

-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0f
target: self
selector: @selector(updateTimer)
userInfo: nil
repeats: YES];
}


- (void)updateTimer
{
if (progressView.progress >= 1.0) {
[timer invalidate];
}
[UIView animateWithDuration:1 animations:^{
float newProgress = [self.progressView progress] + 0.125;
[self.progressView setProgress:newProgress animated:YES];
}];
}

随意调整动画时间以获得更好更平滑的过渡

关于ios - 与 NSTimer 一起使用时,进度条显示滴答动画而不是平滑动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23590365/

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