0
我正在一個iOS項目,我需要顯示增加或減少級聯倒計時的分數。級聯倒計時在UILabel
在這裏,在附加的圖像得分降低15至10,所以動畫將看起來像從15開始滴效果,將在順序14,13,12,11,然後用10去。如圖所示從底部到達頂部。希望你能清楚地看到數字14和13是可見的。
我不確定它是否是一種陰影效果或別的東西。完全卡住了。請建議如何完成這項任務。
感謝
我正在一個iOS項目,我需要顯示增加或減少級聯倒計時的分數。級聯倒計時在UILabel
在這裏,在附加的圖像得分降低15至10,所以動畫將看起來像從15開始滴效果,將在順序14,13,12,11,然後用10去。如圖所示從底部到達頂部。希望你能清楚地看到數字14和13是可見的。
我不確定它是否是一種陰影效果或別的東西。完全卡住了。請建議如何完成這項任務。
感謝
我已經解決了使用3 UILabel
我的問題在一個單一UIView
,並與一些間隔動畫。該過程如下
算法
這裏我添加了我的代碼。
-(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];
}
}];
}
}
您需要一次又一次地調用該方法,直到得分的最後一個值 – 2015-04-04 05:10:33