我有四個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];
}
你可以隨心所欲地運行儘可能多的UIView動畫(在限制範圍內)。你只需要給每一個他們一個獨特的「animationID」(你的@「name」值) –