2011-05-09 5 views
0

작동하지 않습니다 그래서 내 코드입니다 :UIView의 애니메이션

- (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]]]; 
} 

헤더 updateLabel : 나는 updateTotalLabel, 사용자가있는 tableview에 새로운 레코드를 추가 할 때마다 호출 오전

-(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]; 
} 

. 애니메이션은 첫 번째 호출 updateLabel 이후에만 작동하기 때문에 애니메이션에 문제가 있습니다. 각 애니메이션 트리거가있는 경우 출력에 YT

당신이 볼 수

편집

이 좋아, 그래서 나는 영화를 레크 리 에이션.

답변

1

실제로 무슨 일이 일어나고 있는지, 일어나지 않고 있는지에 대한 설명이 없으므로 문제가 무엇인지 잘 모릅니다. 그래도 애니메이션 코드에 문제가 생겼다. 여러 연속 애니메이션을 허용하기 위해 지연을 사용하려고합니다. 그것은 효과가 있을지 모르지만, 나는 정말로 모른다. 그러나 더 좋은 방법은 완성 된 블록을 사용하여 원하는 애니메이션을 계속 진행하는 것입니다. 사용해보기 :

-(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]; 
              }]; 
        }]; 



} 
+0

확인, 업데이트 됨) – juantorena