Skip to content

Commit

Permalink
Add "Extras" (subclass, categories, etc) to repo. [common]
Browse files Browse the repository at this point in the history
  • Loading branch information
cbpowell committed Oct 25, 2016
1 parent 5503217 commit 5b85091
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Extras/NoReturnAnimation.swift
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)
}
}
}
38 changes: 38 additions & 0 deletions Extras/SingleShotOffscreenLabel.swift
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()
}
}
3 changes: 3 additions & 0 deletions MarqueeLabel.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions MarqueeLabelSwift/MarqueeLabelSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
EA017CE81DBED75E00237CA9 /* SingleShotOffscreenLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA017CE71DBED75E00237CA9 /* SingleShotOffscreenLabel.swift */; };
EA017CEA1DBEDCD900237CA9 /* NoReturnAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA017CE91DBEDCD900237CA9 /* NoReturnAnimation.swift */; };
EAE4AC591CA8DAC0006C1ECC /* MLHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = EAE4AC581CA8DAC0006C1ECC /* MLHeader.xib */; };
EAE4AC5B1CA8DAC8006C1ECC /* MarqueeLabel.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EAE4AC5A1CA8DAC8006C1ECC /* MarqueeLabel.storyboard */; };
EAE4AC5F1CA8DAFB006C1ECC /* MarqueeLabelDemoPushController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAE4AC5C1CA8DAFB006C1ECC /* MarqueeLabelDemoPushController.swift */; };
Expand All @@ -20,6 +22,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
EA017CE71DBED75E00237CA9 /* SingleShotOffscreenLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SingleShotOffscreenLabel.swift; path = ../../Extras/SingleShotOffscreenLabel.swift; sourceTree = "<group>"; };
EA017CE91DBEDCD900237CA9 /* NoReturnAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NoReturnAnimation.swift; path = ../../Extras/NoReturnAnimation.swift; sourceTree = "<group>"; };
EA167D021CA8B43700DBF930 /* MarqueeLabelSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MarqueeLabelSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
EA167D111CA8B43700DBF930 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
EAE4AC581CA8DAC0006C1ECC /* MLHeader.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MLHeader.xib; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -53,12 +57,23 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
EA017CE61DBED65E00237CA9 /* Extras */ = {
isa = PBXGroup;
children = (
EA017CE91DBEDCD900237CA9 /* NoReturnAnimation.swift */,
EA017CE71DBED75E00237CA9 /* SingleShotOffscreenLabel.swift */,
);
name = Extras;
path = MarqueeLabelSwift;
sourceTree = "<group>";
};
EA167CF91CA8B43700DBF930 = {
isa = PBXGroup;
children = (
EA167D041CA8B43700DBF930 /* MarqueeLabelSwift Demo */,
EAE4AC801CA8DE70006C1ECC /* MarqueeLabelSwift Framework */,
EA167D031CA8B43700DBF930 /* Products */,
EA017CE61DBED65E00237CA9 /* Extras */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -248,6 +263,8 @@
EAE4ACCF1CAA2495006C1ECC /* MarqueeLabel.swift in Sources */,
EAE4AC661CA8DBBA006C1ECC /* AppDelegate.swift in Sources */,
EAE4AC611CA8DAFB006C1ECC /* MarqueeLabelTableViewController.swift in Sources */,
EA017CE81DBED75E00237CA9 /* SingleShotOffscreenLabel.swift in Sources */,
EA017CEA1DBEDCD900237CA9 /* NoReturnAnimation.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 5b85091

Please sign in to comment.