2012-05-22 37 views
4

我想在UILabel文本上应用动画。我编写代码来增加动画块中的字体大小,但不应用动画。动画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]; 

回答

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是垂直的。请享用!!

+0

一件事是,monthsOnBoard.transform = CGAffineTransformMakeScale(2.0,2.0);应该在[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];之后; –

+0

那么我通常会看到的是在beginAnimations方法之后立即设置每个动画属性(如setAnimationCurve),然后列出要进行动画处理的更改并使用[UIView commitAnimations]。但是,我不认为它有什么区别,提交动画之前的顺序方法应该不重要。说实话,我从来不再使用这种动画方式。你应该寻找阻止动画(他们开始像[UIView animateWithDuration:....],也试试看! –

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