方法一:自己设定时器
定时器以0.12的间隔,不断重复执行函数updateProgress.
适用于帧动画的播放。
NSTimer *progresstimer = [NSTimer scheduledTimerWithTimeInterval:0.12 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];
self.expsUping = 0;
}
}
#pragma mark - 进度条拉动效果
- (void)updateProgress
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
int currentlevel = [[userDefaults objectForKey:@"CurrentLevel"] intValue];
int currentleveltotalscores = [[userDefaults objectForKey:@"CurrentLevelTotalScores"] intValue];
if((self.expsUping <= self.increasedExp) && (self.tmpLevel == currentlevel))
{
self.expsUping++;
self.progressbar.currentValue = self.tmpExp + self.expsUping;
}
else if ((self.expsUping <= self.increasedExp) && (self.tmpLevel < currentlevel))
{
if ((self.expsUping + self.tmpExp) < self.tmpTotalExp) {
self.expsUping++;
self.progressbar.currentValue = self.tmpExp + self.expsUping;
}
else{
self.progressbar.maxValue = currentleveltotalscores;
self.expsUping++;
self.progressbar.currentValue = (self.expsUping + self.tmpExp) - self.tmpTotalExp;
}
}
}
方法二:使用系统库的类
UIImageView *imageView = [[UIImageView alloc] initWithFrame:DF_FRAME((kTABLEVIEW_W-kLOGOMIAO_W_H)/2+15, top_Y, kLOGOMIAO_W_H, kLOGOMIAO_W_H)];
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
for (int i=1; i<13; i++) {
[array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"miao%d",i]]]; //连续帧的存储
}
[view addSubview:imageView];
imageView.animationImages = array;
imageView.animationDuration = 2.0f;
imageView.animationRepeatCount = 2; //重复次数
imageView.image = array[0];
[imageView startAnimating];