Ios 与NSTimer一起使用时,显示勾号动画而不是平滑动画的进度条
我正在使用NSTimer和循环进度条作为倒计时,即15秒 它与以下代码一起工作,但我得到的是进度条的勾号动画,而不是平滑的,如何使其平滑动画Ios 与NSTimer一起使用时,显示勾号动画而不是平滑动画的进度条,ios,objective-c,nstimer,uiprogressview,uiprogressbar,Ios,Objective C,Nstimer,Uiprogressview,Uiprogressbar,我正在使用NSTimer和循环进度条作为倒计时,即15秒 它与以下代码一起工作,但我得到的是进度条的勾号动画,而不是平滑的,如何使其平滑动画 - (void)viewDidLoad { [super viewDidLoad]; self.labeledLargeProgressView.roundedCorners = NO; self.labeledLargeProgressView.trackTintCol
- (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;
}
我自己解决了这个问题。我所做的是更频繁地更新0.1f而不是1.0f
- (void)progressChange
{
CGFloat progress ;
DALabeledCircularProgressView *labeledProgressView = self.labeledLargeProgressView;
if(labeledProgressView.progress >=1.0f && [self.timer isValid]){
[self stopAnimation];
seconds = 15.0f;
_counter = 0;
}
else{
progress=labeledProgressView.progress + 0.00666667f;
_counter ++;
[labeledProgressView setProgress:progress animated:YES];
if(_counter % 10 == 0){
seconds --;
}
labeledProgressView.progressLabel.text = [NSString stringWithFormat:@"%i", seconds];
}
}
- (void)startAnimation
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(progressChange)
userInfo:nil
repeats:YES];
self.continuousSwitch.on = YES;
}
我发现了一组UIview动画和progressview动画,它们工作得更好,并且可以平滑地设置progressview的动画。如果仅使用动画和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];
}];
}
请随意调整动画时间,以获得更好的平滑过渡好的,我自己解决了。。我会更新答案你可能应该删除你的问题;我怀疑这个答案对任何人都有帮助。如果你每0.1秒制作一次动画,你的动画可能仍然不是很流畅。每次屏幕更新时(通常约60 Hz),您都可以使用CADisplayLink获取回调。