2

I am trying to animate CATextLayer's string property so I can put a timestamp to my video using AV Foundation. Does anyone know how to animate this so I can change the string value every second??

james bond
  • 31
  • 3

1 Answers1

2
NSString *labelText = @"foobar";
[textLayer setString:labelText];

This must be run on the main thread, so I use this:

 NSString *labelText = @"foobar";
[textLayer performSelector:@selector(setString:) withObject:labelText waitUntilDone:YES];

And if you are updating frequently, you should disable the animations between the text changes:

NSString *labelText = @"foobar";    
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
[textLayer performSelector:@selector(setString:) withObject:labelText waitUntilDone:YES];
[CATransaction commit];
coneybeare
  • 33,113
  • 21
  • 131
  • 183
  • Thanks, but I dont think this would help. What I am trying to do is to add timestamps to videos (like survalance videos with date and time on ) and then export CATextLayer with my video to .mov file. So I don't really play the video or the CATextLayer to the screen. What I am looking for is something that can do a synchronized change to the string value in CATextLayer with my video when I do my video composition export, something like CAKeyframeAnimation which I can add to my CATextLayer (but I am not sure how to set it up or if it would solve my problem..) Thanks! – james bond Dec 05 '11 at 17:09