Reputation: 11595
I have four NSTimers that work fine. The only problem is that two should fire and then the other two should fire in the middle of the first two. Here is my code:
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];
The initText and initText1 methods create a UILabel with lazy instantiation and place them on the screen on the same spot. The textGlow and textGlow1 methods animate the text to make it grow bigger and fade away. I want initText1 and textGlow1 to fire in the middle of initText and textGlow. For example, let's say each of these methods takes 2 seconds (I set the animation duration to 2 seconds). I want initText and textGlow to fire, and then one second in, initText1 and textGlow1 to fire.
Thanks. If you need any of my other code to help answer the question, just ask.
----------EDIT-------------
@MDT That worked but there is a problem. What I did was I placed the code above of initTimer1 and animateTimer1 in new functions called initTimer1Wrapper and animateTimer1Wrapper. Then I did your code [self performSelector:@selector(initText1Wrapper) withObject:nil afterDelay:1.0];
and duplicated it but changed the selector to animateText1Wrapper. What happens is initText and textGlow will fire as planned, and then also as planned initTimer1 and animateTimer1 will fire one second in, but what also happens unexpectedly is that initText and textGlow do not finish their remaining one second; the animations just stop. I believe this is because they are UIView animations with [UIView beginAnimation:@"name" context:nil]
and [UIView commitAnimations]
and more then 1 UIView animations can't run at the same time.
To fix this, should I use Core Animation (which I do not know anything about) or is there another solution? Thanks.
----------EDIT2-------------
Also, just if it is important for you to know, I will dismiss this animation with a UIGestureRecognizer. Something like:
if(screenIsTapped){
[initTimer invalidate];
[animateTimer invalidate];
[initTimer1 invalidate];
[animateTimer1 invalidate];
}
Upvotes: 0
Views: 164
Reputation: 104082
I think you should do this with 2 timers instead of 4. Inside the methods, initText and initText1 just call textGlow and textGlow1, respectively, using performSelector:withObject:afterDelay: with whatever delay you want. And, do you really want these timers to be repeating? Do you want to keep creating new UILabels?
Upvotes: 0
Reputation: 130193
Try placing something like this inside initText
or textGlow
.
[self performSelector:@selector(initText1) withObject:nil afterDelay:1.0];
Upvotes: 1