0

I'm using an NSTimer to write text to a CATextLayer but the text only displays for a split second.

I set the first timer like this:

-(void) startSentanceAnimation{
    float firstTime = [[sentanceArray objectAtIndex:0][@"time"]floatValue];
    [NSTimer scheduledTimerWithTimeInterval:firstTime target:self    selector:@selector(timedSentances:) userInfo:sentanceArray repeats:NO];

}

It calls this method that changes the text and then creates a new timer.

-(void)timedSentances:(NSTimer *)timer{
    NSArray *userInfo = timer.userInfo;
    timer = nil;
    NSString *sentance = [userInfo objectAtIndex:sentanceCount][@"sentance"];
    [self nextLine:sentance];
    //textLayer.string = sentance;
    float intervalLength =  [[userInfo objectAtIndex:sentanceCount][@"time"]floatValue];
    [NSTimer scheduledTimerWithTimeInterval:intervalLength target:self selector:@selector(timedSentances:) userInfo:userInfo repeats:NO];
    sentanceCount++;

}

The code runs without error, and the text is displayed at the appropriate times, but the text only flashes to the screen for a split second and doesn't persist in between method calls. Is it because I'm not keeping a reference to the timer?

The text should be set using the method nextLine as follows:

-(void)nextLine:(NSString *)st{
    textLayer.string = st;

}

The TextLayer is a CATextLayer and is declared as a variable in the interface like this:

@interface ICIRecordDetail(){
   CATextLayer *textLayer;
}

And it is instantiated in the viewDidLoad method.

I've also tried setting the text like this:

[textLayer setText:sentance];

But the same thing happens. Sentance only appears when the timer fires, and then disappears again. I'm wondering is it because it is in a CATextLayer? Very new to IOS so am at a loss. Any help would be great. thanks

Linda Keating
  • 2,215
  • 7
  • 31
  • 63

0 Answers0