Skip to content

Commit

Permalink
Refactor string consts to enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
lexrus committed Mar 24, 2016
1 parent b312cbd commit e7376a5
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 46 deletions.
8 changes: 4 additions & 4 deletions LTMorphingLabel/LTMorphingLabel+Anvil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension LTMorphingLabel {

func AnvilLoad() {

startClosures["Anvil\(phaseStart)"] = {
startClosures["Anvil\(LTMorphingPhases.Start)"] = {
self.emitterView.removeAllEmitters()

guard self.newRects.count > 0 else { return }
Expand Down Expand Up @@ -166,7 +166,7 @@ extension LTMorphingLabel {
}
}

progressClosures["Anvil\(phaseProgress)"] = {
progressClosures["Anvil\(LTMorphingPhases.Progress)"] = {
(index: Int, progress: Float, isNewChar: Bool) in

if !isNewChar {
Expand All @@ -178,7 +178,7 @@ extension LTMorphingLabel {

}

effectClosures["Anvil\(phaseDisappear)"] = {
effectClosures["Anvil\(LTMorphingPhases.Disappear)"] = {
char, index, progress in

return LTCharacterLimbo(
Expand All @@ -189,7 +189,7 @@ extension LTMorphingLabel {
drawingProgress: 0.0)
}

effectClosures["Anvil\(phaseAppear)"] = {
effectClosures["Anvil\(LTMorphingPhases.Appear)"] = {
char, index, progress in

var rect = self.newRects[index]
Expand Down
12 changes: 6 additions & 6 deletions LTMorphingLabel/LTMorphingLabel+Burn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ extension LTMorphingLabel {

func BurnLoad() {

startClosures["Burn\(phaseStart)"] = {
startClosures["Burn\(LTMorphingPhases.Start)"] = {
self.emitterView.removeAllEmitters()
}

progressClosures["Burn\(phaseProgress)"] = {
progressClosures["Burn\(LTMorphingPhases.Progress)"] = {
index, progress, isNewChar in

if !isNewChar {
Expand All @@ -83,7 +83,7 @@ extension LTMorphingLabel {

}

effectClosures["Burn\(phaseDisappear)"] = {
effectClosures["Burn\(LTMorphingPhases.Disappear)"] = {
char, index, progress in

return LTCharacterLimbo(
Expand All @@ -95,7 +95,7 @@ extension LTMorphingLabel {
)
}

effectClosures["Burn\(phaseAppear)"] = {
effectClosures["Burn\(LTMorphingPhases.Appear)"] = {
char, index, progress in

if char != " " {
Expand Down Expand Up @@ -175,7 +175,7 @@ extension LTMorphingLabel {
)
}

drawingClosures["Burn\(phaseDraw)"] = {
drawingClosures["Burn\(LTMorphingPhases.Draw)"] = {
(charLimbo: LTCharacterLimbo) in

if charLimbo.drawingProgress > 0.0 {
Expand All @@ -192,7 +192,7 @@ extension LTMorphingLabel {
return false
}

skipFramesClosures["Burn\(phaseSkipFrames)"] = {
skipFramesClosures["Burn\(LTMorphingPhases.SkipFrames)"] = {
return 1
}
}
Expand Down
6 changes: 3 additions & 3 deletions LTMorphingLabel/LTMorphingLabel+Evaporate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ extension LTMorphingLabel {

func EvaporateLoad() {

progressClosures["Evaporate\(phaseProgress)"] = {
progressClosures["Evaporate\(LTMorphingPhases.Progress)"] = {
(index: Int, progress: Float, isNewChar: Bool) in
let j: Int = Int(round(cos(Double(index)) * 1.2))
let delay = isNewChar ? self.morphingCharacterDelay * -1.0 : self.morphingCharacterDelay
return min(1.0, max(0.0, self.morphingProgress + delay * Float(j)))
}

effectClosures["Evaporate\(phaseDisappear)"] = {
effectClosures["Evaporate\(LTMorphingPhases.Disappear)"] = {
char, index, progress in

let newProgress = LTEasing.easeOutQuint(progress, 0.0, 1.0, 1.0)
Expand All @@ -55,7 +55,7 @@ extension LTMorphingLabel {
drawingProgress: 0.0)
}

effectClosures["Evaporate\(phaseAppear)"] = {
effectClosures["Evaporate\(LTMorphingPhases.Appear)"] = {
char, index, progress in

let newProgress = 1.0 - LTEasing.easeOutQuint(progress, 0.0, 1.0)
Expand Down
8 changes: 4 additions & 4 deletions LTMorphingLabel/LTMorphingLabel+Fall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension LTMorphingLabel {

func FallLoad() {

progressClosures["Fall\(phaseProgress)"] = {
progressClosures["Fall\(LTMorphingPhases.Progress)"] = {
(index: Int, progress: Float, isNewChar: Bool) in

if isNewChar {
Expand All @@ -53,7 +53,7 @@ extension LTMorphingLabel {

}

effectClosures["Fall\(phaseDisappear)"] = {
effectClosures["Fall\(LTMorphingPhases.Disappear)"] = {
char, index, progress in

return LTCharacterLimbo(
Expand All @@ -64,7 +64,7 @@ extension LTMorphingLabel {
drawingProgress: CGFloat(progress))
}

effectClosures["Fall\(phaseAppear)"] = {
effectClosures["Fall\(LTMorphingPhases.Appear)"] = {

This comment has been minimized.

Copy link
@zxpLearnios
char, index, progress in

let currentFontSize = CGFloat(
Expand All @@ -82,7 +82,7 @@ extension LTMorphingLabel {
}


drawingClosures["Fall\(phaseDraw)"] = {
drawingClosures["Fall\(LTMorphingPhases.Draw)"] = {
limbo in

if limbo.drawingProgress > 0.0 {
Expand Down
6 changes: 3 additions & 3 deletions LTMorphingLabel/LTMorphingLabel+Pixelate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension LTMorphingLabel {

func PixelateLoad() {

effectClosures["Pixelate\(phaseDisappear)"] = {
effectClosures["Pixelate\(LTMorphingPhases.Disappear)"] = {
char, index, progress in

return LTCharacterLimbo(
Expand All @@ -43,7 +43,7 @@ extension LTMorphingLabel {
drawingProgress: CGFloat(progress))
}

effectClosures["Pixelate\(phaseAppear)"] = {
effectClosures["Pixelate\(LTMorphingPhases.Appear)"] = {
char, index, progress in

return LTCharacterLimbo(
Expand All @@ -55,7 +55,7 @@ extension LTMorphingLabel {
)
}

drawingClosures["Pixelate\(phaseDraw)"] = {
drawingClosures["Pixelate\(LTMorphingPhases.Draw)"] = {
limbo in

if limbo.drawingProgress > 0.0 {
Expand Down
12 changes: 6 additions & 6 deletions LTMorphingLabel/LTMorphingLabel+Sparkle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ extension LTMorphingLabel {

func SparkleLoad() {

startClosures["Sparkle\(phaseStart)"] = {
startClosures["Sparkle\(LTMorphingPhases.Start)"] = {
self.emitterView.removeAllEmitters()
}

progressClosures["Sparkle\(phaseProgress)"] = {
progressClosures["Sparkle\(LTMorphingPhases.Progress)"] = {
(index: Int, progress: Float, isNewChar: Bool) in

if !isNewChar {
Expand All @@ -89,7 +89,7 @@ extension LTMorphingLabel {

}

effectClosures["Sparkle\(phaseDisappear)"] = {
effectClosures["Sparkle\(LTMorphingPhases.Disappear)"] = {
char, index, progress in

return LTCharacterLimbo(
Expand All @@ -100,7 +100,7 @@ extension LTMorphingLabel {
drawingProgress: 0.0)
}

effectClosures["Sparkle\(phaseAppear)"] = {
effectClosures["Sparkle\(LTMorphingPhases.Appear)"] = {
char, index, progress in

if char != " " {
Expand Down Expand Up @@ -142,7 +142,7 @@ extension LTMorphingLabel {
)
}

drawingClosures["Sparkle\(phaseDraw)"] = {
drawingClosures["Sparkle\(LTMorphingPhases.Draw)"] = {
(charLimbo: LTCharacterLimbo) in

if charLimbo.drawingProgress > 0.0 {
Expand All @@ -159,7 +159,7 @@ extension LTMorphingLabel {
return false
}

skipFramesClosures["Sparkle\(phaseSkipFrames)"] = {
skipFramesClosures["Sparkle\(LTMorphingPhases.SkipFrames)"] = {
return 1
}
}
Expand Down
23 changes: 10 additions & 13 deletions LTMorphingLabel/LTMorphingLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ import UIKit
import QuartzCore


let phaseStart = "Start"
let phaseAppear = "Appear"
let phaseDisappear = "Disappear"
let phaseDraw = "Draw"
let phaseProgress = "ManipulateProgress"
let phaseSkipFrames = "SkipFrames"
enum LTMorphingPhases: Int {
case Start, Appear, Disappear, Draw, Progress, SkipFrames
}


typealias LTMorphingStartClosure =
Expand Down Expand Up @@ -121,7 +118,7 @@ typealias LTMorphingSkipFramesClosure =
morphingProgress = 0.5
} else if previousText != text {
displayLink.paused = false
let closureKey = "\(morphingEffect.description)\(phaseStart)"
let closureKey = "\(morphingEffect.description)\(LTMorphingPhases.Start)"
if let closure = startClosures[closureKey] {
return closure()
}
Expand Down Expand Up @@ -191,7 +188,7 @@ extension LTMorphingLabel {
if previousText != text && currentFrame < totalFrames + totalDelayFrames + 5 {
morphingProgress += 1.0 / Float(totalFrames)

let closureKey = "\(morphingEffect.description)\(phaseSkipFrames)"
let closureKey = "\(morphingEffect.description)\(LTMorphingPhases.SkipFrames)"
if let closure = skipFramesClosures[closureKey] {
skipFramesCount += 1
if skipFramesCount > closure() {
Expand Down Expand Up @@ -282,7 +279,7 @@ extension LTMorphingLabel {

// Override morphing effect with closure in extenstions
if let closure = effectClosures[
"\(morphingEffect.description)\(phaseDisappear)"
"\(morphingEffect.description)\(LTMorphingPhases.Disappear)"
] {
return closure(char, index: index, progress: progress)
} else {
Expand Down Expand Up @@ -320,7 +317,7 @@ extension LTMorphingLabel {
)

if let closure = effectClosures[
"\(morphingEffect.description)\(phaseAppear)"
"\(morphingEffect.description)\(LTMorphingPhases.Appear)"
] {
return closure(char, index: index, progress: progress)
} else {
Expand Down Expand Up @@ -350,7 +347,7 @@ extension LTMorphingLabel {
var progress: Float = 0.0

if let closure = progressClosures[
"\(morphingEffect.description)\(phaseProgress)"
"\(morphingEffect.description)\(LTMorphingPhases.Progress)"
] {
progress = closure(index: i, progress: morphingProgress, isNewChar: false)
} else {
Expand All @@ -370,7 +367,7 @@ extension LTMorphingLabel {
var progress: Float = 0.0

if let closure = progressClosures[
"\(morphingEffect.description)\(phaseProgress)"
"\(morphingEffect.description)\(LTMorphingPhases.Progress)"
] {
progress = closure(index: i, progress: morphingProgress, isNewChar: true)
} else {
Expand Down Expand Up @@ -426,7 +423,7 @@ extension LTMorphingLabel {

let willAvoidDefaultDrawing: Bool = {
if let closure = drawingClosures[
"\(morphingEffect.description)\(phaseDraw)"
"\(morphingEffect.description)\(LTMorphingPhases.Draw)"
] {
return closure($0)
}
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion LTMorphingLabelDemo/LTDemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LTDemoViewController : UIViewController, LTMorphingLabelDelegate {
"老婆和女儿"
]
private var text: String {
i = i >= textArray.count ? 0 : i + 1
i = i >= textArray.count - 1 ? 0 : i + 1
return textArray[i]
}

Expand Down
9 changes: 3 additions & 6 deletions LTMorphingLabelDemo/Launch Screen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9060" systemVersion="15C27e" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<scenes>
Expand All @@ -17,22 +17,19 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright © 2015 lexrus.com. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright © 2016 lexrus.com. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
<rect key="frame" x="20" y="559" width="560" height="21"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.12908115671641796" green="0.12908115671641796" blue="0.12908115671641796" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="LTMorphingLabelDemo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
<rect key="frame" x="20" y="180" width="560" height="43"/>
<animations/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" red="0.11456389925373134" green="0.11456389925373134" blue="0.11456389925373134" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
Expand Down

0 comments on commit e7376a5

Please sign in to comment.