-
-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Extras" (subclass, categories, etc) to repo. [common]
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// NoAnimationReturn.swift | ||
// MarqueeLabel | ||
// | ||
// Created by Charles Powell on 10/23/16. | ||
// Copyright © 2016 Charles Powell. All rights reserved. | ||
|
||
import UIKit | ||
|
||
open class NoAnimationReturn: MarqueeLabel { | ||
// Override labelWillBeginScroll to catch when a scroll animation starts | ||
override open func labelWillBeginScroll() { | ||
// This only makes sense for leftRight and rightLeft types | ||
if type == .leftRight || type == .rightLeft { | ||
// Calculate "away" position time after scroll start | ||
let awayTime = animationDelay + animationDuration | ||
// Schedule a timer to restart the label when it hits the "away" position | ||
Timer.scheduledTimer(timeInterval: TimeInterval(awayTime), target: self, selector: #selector(restartLabel), userInfo: nil, repeats: false) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// SingleShotOffscreenLabel.swift | ||
// MarqueeLabelSwift | ||
// | ||
// Created by Charles Powell on 10/24/16. | ||
// Copyright © 2016 Charles Powell. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
open class SingleShotOffscreenLabel: MarqueeLabel { | ||
// Override layoutSubviews to catch frame size changes | ||
open override func layoutSubviews() { | ||
// Set trailingBuffer to frame width + 10 (to be sure) | ||
trailingBuffer = frame.width | ||
super.layoutSubviews() | ||
} | ||
|
||
// Override labelWillBeginScroll to catch when a scroll animation starts | ||
open override func labelWillBeginScroll() { | ||
// This only makes sense for leftRight and rightLeft types | ||
if type == .leftRight || type == .rightLeft { | ||
// Calculate "away" position time after scroll start | ||
let awayTime = animationDelay + animationDuration | ||
// Schedule a timer to restart the label when it hits the "away" position | ||
Timer.scheduledTimer(timeInterval: TimeInterval(awayTime), target: self, selector: #selector(pauseAndClear), userInfo: nil, repeats: false) | ||
} | ||
} | ||
|
||
public func pauseAndClear() { | ||
// Pause label offscreen | ||
pauseLabel() | ||
// Change text to nil | ||
text = nil | ||
// Unpause (empty) label, clearing the way for a subsequent text change to trigger scroll | ||
unpauseLabel() | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters