正常に動作するNSTimerが4つあります。唯一の問題は、2つが発砲し、他の2つが最初の2つの途中で発砲することです。これが私のコードです:
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を起動してから、1秒後にinitText1とtextGlow1を起動します。
ありがとう。質問に答えるのに役立つ他のコードが必要な場合は、質問してください。
- - - - - 編集 - - - - - - -
@MDT動作しましたが、問題があります。私がしたことは、initTimer1とanimateTimer1の上記のコードをinitTimer1WrapperとanimateTimer1Wrapperと呼ばれる新しい関数に配置することでした。次に、コード[self performSelector:@selector(initText1Wrapper) withObject:nil afterDelay:1.0];
を作成して複製しましたが、セレクターをanimateText1Wrapperに変更しました。何が起こるかというと、initTextとtextGlowは計画どおりに起動し、次に計画どおりにinitTimer1とanimateTimer1が1秒で起動しますが、予期せずに発生するのは、initTextとtextGlowが残りの1秒を終了しないことです。アニメーションは停止します。これは、UIViewアニメーションで[UIView beginAnimation:@"name" context:nil]
あり[UIView commitAnimations]
、1つ以上のUIViewアニメーションを同時に実行できないためだと思います。
これを修正するには、Core Animation(私は何も知りません)を使用する必要がありますか、それとも別の解決策がありますか?ありがとう。
----------編集2-------------
また、知っておくことが重要な場合は、UIGestureRecognizerを使用してこのアニメーションを却下します。何かのようなもの:
if(screenIsTapped){
[initTimer invalidate];
[animateTimer invalidate];
[initTimer1 invalidate];
[animateTimer1 invalidate];
}