2010-07-02 67 views
0

HI all, 我想將UILabel向上移動5秒並隱藏起來。 我們在遊戲中看到的東西,當我們得到布魯斯什麼的時候, 文字出現,向上移動說什麼「+300」等。將UILabel向上移動NSTimer

如何移動UIlabel? 問候

回答

1

看一看在UIView animation methods

- (void)showScoreLabelFor:(int)score { 
    // Make a label 
    UILabel *scoreLabel = [UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] autorelease]; 

    // Set it's text to the score we want to show 
    [scoreLabel setText:[NSString stringWithFormat:@"%+i", score]]; 

    // Center it in the view 
    [scoreLabel sizeToFit]; 
    [scoreLabel setCenter:CGPointMake([[self view] center].x, 200)]; 

    // Add it to the view 
    [[self view] addSubview:scoreLabel]; 

    // Animate it up 100 pixels ver 2 seconds 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:2.0]; 
    CGRect frame = [scoreLabel frame]; 
    frame.origin.y -= 100; 
    [scoreLabel setFrame:frame]; 
    [UIView commitAnimations]; 
} 
+0

__beginAnimations__和__commitAnimations__之間的任何內容動畫 - 所以,如果我設置標籤的y位置要高100將標籤滑到增加100px。如果你編輯你的問題,並添加你遇到麻煩的代碼,我可以看看。 – deanWombourne 2010-07-02 14:25:59

+0

我只需要顯示一個文字說「+ 500」 顯示向上移動和3-4秒後,它應該隱藏。 謝謝,我真的很感謝你的幫助 – iscavengers 2010-07-02 14:34:45

+0

我已經編輯了我的問題,使它成爲一個方法,將s標籤放在viewcontrollers視圖上,並在2秒內將它的動畫增加100px。使用它像__ [自我showScoreLabelFor:200]; __ – deanWombourne 2010-07-02 14:50:59