나는 하나의 UIView
에 3 UILabel
를 사용하여 내 문제를 해결하고 약간의 간격을 애니메이션했습니다.
알고리즘 텍스트 2 라벨 (점수) 어떤 값으로 스케일을 설정
- 를 다음과 같은 방법이다.
- 다음 점수 값으로 세 번째 레이블을 설정하십시오.
- 두 번째 레이블을 0 (식별)까지 낮추고 첫 번째 레이블의 위치에 놓습니다.
- 마찬가지로 세 번째 레이블을 두 번째 위치로 확대합니다. 첫 번째 레이블을 마지막 위치로 이동하십시오.
- 다음 점수 값을 세 번째 레이블로 설정하십시오.
- 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];
}
}];
}
}
점수를 마지막 값까지 몇 번이나 다시 호출해야합니다. –