[英]Circular Progress bar / PIE for countdown timer
我的應用程序在圓形進度條動畫中需要15秒計時器,該動畫將在秒中心保留標簽
下面的代碼將labelprogress從0.0擴展到1.0f,但是如果要使用定時器擴展程序,我還要將其映射到平滑動畫的15秒倒計時,而不是應該使用平滑動畫添加時間
例如:首先,我需要從15秒開始,如果用戶單擊timeextender通電,並且當前時間是10秒,則應該是25秒,因此進度條百分比應該可以工作。
所以我需要映射什么邏輯才能完成上述要求
- (void)progressChange
{
// Labeled progress views
NSArray *labeledProgressViews = @[//self.labeledProgressView,
self.labeledLargeProgressView];
for (DALabeledCircularProgressView *labeledProgressView in labeledProgressViews) {
CGFloat progress = ![self.timer isValid] ? self.stepper.value / 10.0f : labeledProgressView.progress + 0.01f;
[labeledProgressView setProgress:progress animated:YES];
labeledProgressView.progressLabel.text = [NSString stringWithFormat:@"%.2f", labeledProgressView.progress];
}
}
- (void)startAnimation
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.03
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;
}
- (IBAction)TimeExtender:(id)sender
{
if (labeledProgressView.progress >= 1.0f && [self.timer isValid]) {
[labeledProgressView setProgress:0.f animated:YES];
}
}
我自己解決了這是代碼
- (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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.