动画UILabel文本大小增加和减少

时间:2012-05-22 05:21:38

标签: iphone ios

我想在UILabel文本上应用动画。我编写代码来增加动画块中的字体大小,但不应用动画。

[UIView beginAnimations:nil context:nil/*contextPoint*/];
    monthsOnBoard.font=[UIFont fontWithName:@"digital-7" size:150];
    daysOnBoard.font=[UIFont fontWithName:@"digital-7" size:150];
    hoursOnBoard.font=[UIFont fontWithName:@"digital-7" size:100];
    minutesOnBoard.font=[UIFont fontWithName:@"digital-7" size:100];
    secondsOnBoard.font=[UIFont fontWithName:@"digital-7" size:100];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDelay:0.5];
    [UIView setAnimationDuration:1];
    [UIView setAnimationRepeatCount:4];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView commitAnimations];

2 个答案:

答案 0 :(得分:10)

UIView的字体不是可动画的属性。你应该改用变换。

[UIView beginAnimations:nil context:nil/*contextPoint*/];
monthsOnBoard.transform = CGAffineTransformMakeScale(2.0, 2.0); //increase the size by 2
 //etc etc same procedure for the other labels.
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView commitAnimations];

类似地,您可以使用CGAffineTransformMakeScale(x, y);中的值进行播放 - x是水平刻度常量,y是垂直刻度常量。享受!!

答案 1 :(得分:1)

它可能对你有帮助

 monthsOnBoard.transform = CGAffineTransformScale(monthsOnBoard.transform, 1, 1); 
    [UIView beginAnimations:nil context:nil/*contextPoint*/];
    monthsOnBoard.transform = CGAffineTransformScale(monthsOnBoard.transform, 4, 4); 
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDelay:0.5];
    [UIView setAnimationDuration:1];
    [UIView setAnimationRepeatCount:4];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView commitAnimations];