Have a property to avoid looping
Closed this issue · 1 comments
It would be nice to have an option to perform the animation only once and avoid the looping. Maybe there's an option already, but I haven't found it :(
A property like _numberOfRepetitions_, where you can also set 0 (or -1) for infinite looping, would be awesome.
Actually you can do the first half! It's not as straightforward as a single property, but you can immediately set the holdScrolling = true
after creating the MarqueeLabel, and then call triggerScrollStart()
at the appropriate time to trigger a scroll loop. That method overrides the holdScrolling
property only once, so the label will stop scrolling once it completes a loop (at which point you could trigger it again, if you wanted).
I can see a few potential issues with implementing a numberOfRepetitions
property, because MarqueeLabel (as a UIView) doesn't necessarily know what it's container UIViewController is doing. I think to do it right, you might want to subclass MarqueeLabel and integrate it more closely with your UIViewController, since you know exactly what you what to do (i.e. when does the count of loops get reset?).
You can subclass MarqueeLabel and override the labelReturnedToHome(finished: Bool)
property to keep track of when a loop finishes, and maybe increment/decrement a numberOfRepetitions
property (also added to the subclass). When that count meets the right number, you can set holdScrolling == true
to prevent the next loop. Your view controller can then adjust this count value and holdScrolling
when appropriate. Hope this helps!