Итак, это мой код:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 0) {
if (!header) {
header = [[CustomBackground alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
float number = [self.total floatValue];
[self updateTotalLabel: &number];
}
return header;
}
return nil;
}
-(void)updateTotalLabel:(float *)amount
{
float currentValue = [self.total floatValue];
self.total = [NSNumber numberWithFloat:(currentValue + *amount)];
[header updateLabel:[NSString stringWithFormat:TOTAL, [total floatValue]]];
}
header updateLabel:
-(void)updateLabel:(NSString *)string
{
CGRect frame = self.frame;
frame.origin.y = -frame.size.height;
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^{
self.frame = frame;
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
self.frame = frame;
frame.origin.y = 0;
self.label.text = string;
[UIView animateWithDuration:0.5
delay:1.0
options: UIViewAnimationTransitionCurlDown
animations:^{
self.frame = frame;
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
[label setNeedsDisplay];
}
Я звоню updateTotalLabel каждый раз, когда пользователь добавляет новую запись в табличное представление.У меня проблема с анимацией, потому что анимация работает только после первого вызова updateLabel.
РЕДАКТИРОВАТЬ
Хорошо, поэтому я записываю фильм: YT
На выходе вы можете видеть, когда запускается каждая анимация.