2012-06-03 82 views
0

我有四個NSTimers工作正常。唯一的問題是兩個人應該開火,然後另外兩個人應該在前兩個人中間開火。這裏是我的代碼:搖擺NSTimer火災

initTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector: @selector(initText) userInfo:nil repeats:YES]; 
    animateTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector: @selector(textGlow) userInfo:nil repeats:YES]; 
    initTimer1 = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector: @selector(initText1) userInfo:nil repeats:YES]; 
    animateTimer1 = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector: @selector(textGlow1) userInfo:nil repeats:YES]; 

的initText和initText1方法創建一個UILabel懶實例化,並把他們放在同一個點在屏幕上。 textGlow和textGlow1方法使文本動起來,使其變得更大並消失。我想initText1和textGlow1在initText和textGlow的中間觸發。例如,假設每個方法都需要2秒(我將動畫持續時間設置爲2秒)。我想initText和textGlow觸發,然後在initText1和textGlow1中觸發一秒。

謝謝。如果您需要我的其他代碼來幫助回答問題,請詢問。

----------編輯-------------

@MDT這工作,但有一個問題。我所做的是將initTimer1和animateTimer1的代碼放在名爲initTimer1Wrapper和animateTimer1Wrapper的新函數中。然後我做了你的代碼[self performSelector:@selector(initText1Wrapper) withObject:nil afterDelay:1.0];並複製它,但將選擇器更改爲animateText1Wrapper。 initText和textGlow會按計劃觸發,然後按照計劃initTimer1和animateTimer1將觸發一秒鐘,但意外的是initText和textGlow還沒有完成剩餘的一秒;動畫只是停止。我相信這是因爲他們是與[UIView beginAnimation:@"name" context:nil][UIView commitAnimations] UIView動畫和多個1 UIView動畫不能同時運行。

要解決這個問題,我應該使用Core Animation(我什麼都不知道)還是有其他解決方案?謝謝。

---------- EDIT2 -------------

而且,只是如果是重要的,你要知道,我會關閉這與動畫一個UIGestureRecognizer。 喜歡的東西:

if(screenIsTapped){ 
    [initTimer invalidate]; 
    [animateTimer invalidate]; 
    [initTimer1 invalidate]; 
    [animateTimer1 invalidate]; 
} 
+0

你可以隨心所欲地運行儘可能多的UIView動畫(在限制範圍內)。你只需要給每一個他們一個獨特的「animationID」(你的@「name」值) –

回答

1

試着將這樣的事情裏面initTexttextGlow

[self performSelector:@selector(initText1) withObject:nil afterDelay:1.0]; 
+0

看到我上面的第一個編輯。 – pasawaya

0

我想你應該有2個定時器,而不是4裏面的方法做到這一點,initText和initText1只是調用分別textGlow和textGlow1,使用performSelector:withObject:afterDelay:與任何耽誤你想要的。而且,你真的希望這些定時器重複嗎?你想不斷創造新的UILabels?

+0

是的,因爲這正是我想要做的事情,應用程序會打開帶有我的標誌的啓動圖像,然後文本顯示「點擊進入」,並且此文本將保持動畫效果,直到用戶點擊屏幕上,動畫如下:文本「點擊進入」出現在屏幕上,然後變得越來越大,越來越不透明,越來越大,直到它消失,但在這個動畫的中間,同樣的動畫再次發生。initText和textGlow方法分別創建標籤並對它們進行動畫處理,initText1和textGlow1方法將成爲動畫 – pasawaya

+0

中斷第一個動畫通貨膨脹。 – pasawaya

+0

我會嘗試你的想法,看看它是否有效。 – pasawaya