Note that there are some explanatory texts on larger screens.

plurals
  1. PONSTimer scheduledTimerWithTimeInterval and CoreAnimation
    primarykey
    data
    text
    <p>I am writing an app using a cocoa control that animates text,</p> <p><strong><a href="https://www.cocoacontrols.com/controls/marqueelabel" rel="nofollow">https://www.cocoacontrols.com/controls/marqueelabel</a></strong></p> <p>It uses <code>CoreText</code> and <code>QuartzCore</code>.</p> <p>It's a pretty great control, but i'm having trouble. When instantiated the animated labels that I create using the control start to scroll immediately, however I'm finding that when I create an animated label using <code>NSTimer</code> it is not animating. I am using</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; .... [self.view addSubview:continuousLabel1]; [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(updatePrice) userInfo:nil repeats:YES]; } </code></pre> <p>to call a method that creates the animated label, when I call the method directly the labels create and animate, however when called using the above scheduled timer, new labels created only animate on the first call, not on the timers repeat calls to the method. I have checked that my method is being call on the main thread/ main runloop, any ideas?</p> <p>For clarity the work flow is:</p> <p>Timer calls method --> Label 1 is created and starts to Animate.</p> <p>5 Seconds Late...</p> <p>Timer calls method again --> Label 2 is created However is does not begin to animate as expected.</p> <p>EDIT:</p> <pre><code>- (void)updatePrice { MarqueeLabel *continuousLabel2 = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10, 230, self.view.frame.size.width-20, 20) rate:100.0f andFadeLength:10.0f]; continuousLabel2.tag = 101; continuousLabel2.marqueeType = MLContinuous; continuousLabel2.animationCurve = UIViewAnimationOptionCurveLinear; continuousLabel2.continuousMarqueeExtraBuffer = 50.0f; continuousLabel2.numberOfLines = 1; continuousLabel2.opaque = NO; continuousLabel2.enabled = YES; continuousLabel2.shadowOffset = CGSizeMake(0.0, -1.0); continuousLabel2.textAlignment = NSTextAlignmentLeft; continuousLabel2.textColor = [UIColor colorWithRed:0.234 green:0.234 blue:0.234 alpha:1.000]; continuousLabel2.backgroundColor = [UIColor clearColor]; continuousLabel2.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.000]; continuousLabel2.text = @"This is another long label that doesn't scroll continuously with a custom space between labels! You can also tap it to pause and unpause it!"; [self.view addSubview:continuousLabel2]; if( [NSThread isMainThread]) { NSLog(@"In Main Thread"); } if ([NSRunLoop currentRunLoop] == [NSRunLoop mainRunLoop]) { NSLog(@"In Main Loop"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload