2012-06-11 94 views
0

我正在製作一個遊戲項目,我想要做的是將一組標籤從窗口頂部移到窗口底部,讓用戶閱讀這些標籤並消失(像標籤從上到下滑動而沒有任何觸發)。Objective C moving Labels

我認爲循環中的計時器變量將幫助我滑動並根據計時器值更改其位置。

我做了一些研究,但如果你與我分享一篇文章,我可以知道我應該查找什麼。

謝謝。

回答

2

@Chuck是對的。詳細說明:

-(void)doTheLabelThing { 

    // assume all the labels are in a container view that is 320 wide and 100 tall 
    self.labelContainer.frame = CGRectMake(0, -100, 320, 100); 

    [UIView animateWithDuration:0.5 animations:^{ 
     // slide down 
     self.labelContainer.frame = CGRectMake(0, 360, 320, 100); 
    } completion:^(BOOL finished) { 
     // give user 3 seconds to read it 
     [UIView animateWithDuration:0.5 delay:3.0 options:0 animations:^{ 
      // fade out 
      self.labelContainer.alpha = 0.0; 
     } completion:^(BOOL finished) { 
      // restore everything to original state 
      self.labelContainer.alpha = 1.0; 
      self.labelContainer.frame = CGRectMake(0, -100, 320, 100); 
     }]; 
    }]; 
} 
+0

這很有幫助,讓我意識到邏輯,謝謝。 –

1

不要使用循環或計時器;使用核心動畫。只需做animateWithDuration:animations:或類似的工作,並將他們的位置設置爲您希望他們成爲的新地點。

+0

謝謝你的想法。 –