2012-05-22 51 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];