2014-09-25 7 views
0

캐스케이드 카운트 다운 방식으로 점수를 높이거나 낮추어야하는 iOS 프로젝트에서 일하고 있습니다. 애니메이션 (15)로부터 시작하여 하강 효과처럼 나타난다 순서 14, 13, 12, 11 그리고 10에 갈 수 있도록 여기에 첨부 된 이미지 점수 UILabel에서 캐스케이드 카운트 다운

enter image description here

15 내지 10이 감소된다. 아래에서 오는 이미지에 표시된대로 상단에 도달. 14 번과 13 번을 분명히 볼 수 있기를 바랍니다.

그림자 효과 또는 다른 종류인지 확실하지 않습니다. 완전히 붙어있어. 이 작업을 수행하는 방법을 제안하십시오.

덕분에

답변

0

나는 하나의 UIView에 3 UILabel를 사용하여 내 문제를 해결하고 약간의 간격을 애니메이션했습니다.

알고리즘 텍스트 2 라벨 (점수) 어떤 값으로 스케일을 설정

  1. 를 다음과 같은 방법이다.
  2. 다음 점수 값으로 세 번째 레이블을 설정하십시오.
  3. 두 번째 레이블을 0 (식별)까지 낮추고 첫 번째 레이블의 위치에 놓습니다.
  4. 마찬가지로 세 번째 레이블을 두 번째 위치로 확대합니다. 첫 번째 레이블을 마지막 위치로 이동하십시오.
  5. 다음 점수 값을 세 번째 레이블로 설정하십시오.
  6. 1 ~ 5 단계를 마지막 점수 값까지 반복합니다. 애니메이션을 중단하십시오.

여기에 내 코드가 추가됩니다.

-(void)animateForLabel:(UILabel *)scoreLabel 
{ 
    if (shouldAnimate) 
    { 
     //I've placed 3 labels on a view. Object at index 2 will be on top 
     UILabel *lbl1 = [[animationLayer subviews] objectAtIndex:2]; //Top label 
     UILabel *lbl2 = [[animationLayer subviews] objectAtIndex:1]; //Middle Label 
     UILabel *lbl3 = [[animationLayer subviews] objectAtIndex:0]; //Bottom Label 

     lbl1.transform = CGAffineTransformIdentity; //Setting first label to its original position 
     [lbl1 setFrame:CGRectMake(0, 50, lbl1.frame.size.width, lbl1.frame.size.height)]; 

     //Setting View Position, This something you can set the Label's Superview position to their superview 
     [animationLayer setFrame:[self convertFrameForLabel:scoreLabel]]; 
     [lbl2 setCenter:CGPointMake(animationLayer.frame.size.width/2, lbl2.center.y)]; 
     [lbl3 setCenter:CGPointMake(animationLayer.frame.size.width/2, lbl3.center.y)]; 

     [self addTextToAnimationLabel:lbl1]; //Adding the new value to the the desired label 
     [lbl1 setCenter:CGPointMake(animationLayer.frame.size.width/2, lbl1.center.y + 10)]; 
     lbl1.layer.opacity = 0.0; //Setting its opacity to zero so that it will look invisible. 


     double durationInSeconds = 0.1; 

     [UIView animateWithDuration:durationInSeconds delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{ 
      [lbl1 setCenter:CGPointMake(lbl1.center.x, lbl1.center.y - 10)]; 
      lbl1.layer.opacity = 0.3; // Setting their opacity according to the need 
      lbl2.layer.opacity = 0.6; // Same as above 
      lbl3.layer.opacity = 0.8; // Same as above 

      lbl3.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.2, 1.2); 
      lbl2.transform = CGAffineTransformScale(lbl2.transform, 1.8, 1.8); // Setting scale so that the animation flow must be visible as curve shape 

      lbl3.center = CGPointMake(lbl3.center.x, 7); 
      lbl2.center = CGPointMake(lbl2.center.x, 30); 
    } completion:^(BOOL finished) { 
      NSLog(@"Complete animation"); 
      if ([scoreLabel isEqual:creatorScoreLbl]) 
       [self setWidthIfCreatorScoreChanged:[lbl3.text integerValue]]; 
      else 
       [self setWidthIfOpponentScoreChanged:[lbl3.text integerValue]]; 
      [animationLayer insertSubview:lbl3 atIndex:2]; 
      if (![lbl3.text isEqualToString:@""] && [lbl3.text integerValue] == toScore) 
      { 
       shouldAnimate=NO; 
       [audioService stopPlaying]; 
       [animationLayer removeFromSuperview]; 
      } 
      else 
      { 
       [self animateForLabel:scoreLabel]; 
      } 
     }]; 
    } 
} 
+0

점수를 마지막 값까지 몇 번이나 다시 호출해야합니다. –