Reputation: 71
So it is my code:
- (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];
}
I am calling updateTotalLabel, every time when user adds new record to tableview. I have a problem with animation because, animation works only after first call updateLabel.
EDIT
Ok, so I rec a movie: YT
In output you can see when each animation is trigger.
Upvotes: 0
Views: 1053
Reputation: 7265
Not really sure what your problem is, as there is really no description of what is happening and what is not happening. I do see a problem with your animation code though. You're attempting to use delays to allow for multiple continuous animations. It might work, I really don't know. However, a better method is just to use the completion block to continue with what ever animation you want. Try this:
-(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 1!");
frame.origin.y = 0;
self.label.text = string;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationTransitionCurlDown
animations:^{
self.frame = frame;
}
completion:^(BOOL finished){
NSLog(@"Done 2!");
[label setNeedsDisplay];
}];
}];
}
Upvotes: 1