Skip to content

Commit

Permalink
Confirm to Tailor.
Browse files Browse the repository at this point in the history
  • Loading branch information
lexrus committed Dec 21, 2015
1 parent 53a8e9e commit 13a73ec
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 41 deletions.
4 changes: 4 additions & 0 deletions .tailor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exclude:
- 'Pods'
- 'Carthage'
- 'LTMorphingLabelDemo'
2 changes: 1 addition & 1 deletion LTMorphingLabel/LTCharacterLimbo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import UIKit


public struct LTCharacterLimbo : CustomDebugStringConvertible {
public struct LTCharacterLimbo: CustomDebugStringConvertible {

public let char: Character
public var rect: CGRect
Expand Down
1 change: 1 addition & 0 deletions LTMorphingLabel/LTEasing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ public struct LTEasing {
}
}(t / d)
}

}
4 changes: 3 additions & 1 deletion LTMorphingLabel/LTEmitterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public struct LTEmitter {

image = UIImage(named: particleName)

if image != nil {
return
}
// Load from Framework
if image != nil { return }
image = UIImage(
named: particleName,
inBundle: NSBundle(forClass: LTMorphingLabel.self),
Expand Down
3 changes: 2 additions & 1 deletion LTMorphingLabel/LTMorphingEffect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import UIKit


@objc public enum LTMorphingEffect : Int, CustomStringConvertible {
@objc public enum LTMorphingEffect: Int, CustomStringConvertible {

case Scale = 0
case Evaporate
Expand Down Expand Up @@ -60,4 +60,5 @@ import UIKit
return "Scale"
}
}

}
4 changes: 2 additions & 2 deletions LTMorphingLabel/LTMorphingLabel+Anvil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ extension LTMorphingLabel {
}

effectClosures["Anvil\(phaseDisappear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

return LTCharacterLimbo(
char: char,
Expand All @@ -190,7 +190,7 @@ extension LTMorphingLabel {
}

effectClosures["Anvil\(phaseAppear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

var rect = self.newRects[index]

Expand Down
6 changes: 3 additions & 3 deletions LTMorphingLabel/LTMorphingLabel+Burn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extension LTMorphingLabel {
}

progressClosures["Burn\(phaseProgress)"] = {
(index: Int, progress: Float, isNewChar: Bool) in
index, progress, isNewChar in

if !isNewChar {
return min(1.0, max(0.0, progress))
Expand All @@ -84,7 +84,7 @@ extension LTMorphingLabel {
}

effectClosures["Burn\(phaseDisappear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

return LTCharacterLimbo(
char: char,
Expand All @@ -96,7 +96,7 @@ extension LTMorphingLabel {
}

effectClosures["Burn\(phaseAppear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

if char != " " {
let rect = self.newRects[index]
Expand Down
4 changes: 2 additions & 2 deletions LTMorphingLabel/LTMorphingLabel+Evaporate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension LTMorphingLabel {
}

effectClosures["Evaporate\(phaseDisappear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

let newProgress = LTEasing.easeOutQuint(progress, 0.0, 1.0, 1.0)
let yOffset: CGFloat = -0.8 * CGFloat(self.font.pointSize) * CGFloat(newProgress)
Expand All @@ -56,7 +56,7 @@ extension LTMorphingLabel {
}

effectClosures["Evaporate\(phaseAppear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

let newProgress = 1.0 - LTEasing.easeOutQuint(progress, 0.0, 1.0)
let yOffset = CGFloat(self.font.pointSize) * CGFloat(newProgress) * 1.2
Expand Down
24 changes: 12 additions & 12 deletions LTMorphingLabel/LTMorphingLabel+Fall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension LTMorphingLabel {
}

effectClosures["Fall\(phaseDisappear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

return LTCharacterLimbo(
char: char,
Expand All @@ -65,7 +65,7 @@ extension LTMorphingLabel {
}

effectClosures["Fall\(phaseAppear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

let currentFontSize = CGFloat(
LTEasing.easeOutQuint(progress, 0.0, Float(self.font.pointSize))
Expand All @@ -83,21 +83,21 @@ extension LTMorphingLabel {


drawingClosures["Fall\(phaseDraw)"] = {
(charLimbo: LTCharacterLimbo) in
limbo in

if charLimbo.drawingProgress > 0.0 {
if limbo.drawingProgress > 0.0 {
let context = UIGraphicsGetCurrentContext()
var charRect = charLimbo.rect
var charRect = limbo.rect
CGContextSaveGState(context)
let charCenterX = charRect.origin.x + (charRect.size.width / 2.0)
var charBottomY = charRect.origin.y + charRect.size.height - self.font.pointSize / 6
var charColor = self.textColor

// Fall down if drawingProgress is more than 50%
if charLimbo.drawingProgress > 0.5 {
if limbo.drawingProgress > 0.5 {
let ease = CGFloat(
LTEasing.easeInQuint(
Float(charLimbo.drawingProgress - 0.4),
Float(limbo.drawingProgress - 0.4),
0.0,
1.0,
0.5
Expand All @@ -108,7 +108,7 @@ extension LTMorphingLabel {
1.0,
max(
0.0,
charLimbo.drawingProgress * -2.0 + 2.0 + 0.01
limbo.drawingProgress * -2.0 + 2.0 + 0.01
)
)
charColor = self.textColor.colorWithAlphaComponent(fadeOutAlpha)
Expand All @@ -121,21 +121,21 @@ extension LTMorphingLabel {
height: charRect.size.height)
CGContextTranslateCTM(context, charCenterX, charBottomY)

let angle = Float(sin(Double(charLimbo.rect.origin.x)) > 0.5 ? 168 : -168)
let angle = Float(sin(Double(limbo.rect.origin.x)) > 0.5 ? 168 : -168)
let rotation = CGFloat(
LTEasing.easeOutBack(
min(
1.0,
Float(charLimbo.drawingProgress)
Float(limbo.drawingProgress)
),
0.0,
1.0
) * angle
)
CGContextRotateCTM(context, rotation * CGFloat(M_PI) / 180.0)
let s = String(charLimbo.char)
let s = String(limbo.char)
s.drawInRect(charRect, withAttributes: [
NSFontAttributeName: self.font.fontWithSize(charLimbo.size),
NSFontAttributeName: self.font.fontWithSize(limbo.size),
NSForegroundColorAttributeName: charColor
])
CGContextRestoreGState(context)
Expand Down
14 changes: 7 additions & 7 deletions LTMorphingLabel/LTMorphingLabel+Pixelate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension LTMorphingLabel {
func PixelateLoad() {

effectClosures["Pixelate\(phaseDisappear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

return LTCharacterLimbo(
char: char,
Expand All @@ -44,7 +44,7 @@ extension LTMorphingLabel {
}

effectClosures["Pixelate\(phaseAppear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

return LTCharacterLimbo(
char: char,
Expand All @@ -56,16 +56,16 @@ extension LTMorphingLabel {
}

drawingClosures["Pixelate\(phaseDraw)"] = {
(charLimbo: LTCharacterLimbo) in
limbo in

if charLimbo.drawingProgress > 0.0 {
if limbo.drawingProgress > 0.0 {

let charImage = self.pixelateImageForCharLimbo(
charLimbo,
withBlurRadius: charLimbo.drawingProgress * 6.0
limbo,
withBlurRadius: limbo.drawingProgress * 6.0
)

charImage.drawInRect(charLimbo.rect)
charImage.drawInRect(limbo.rect)

return true
}
Expand Down
4 changes: 2 additions & 2 deletions LTMorphingLabel/LTMorphingLabel+Sparkle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension LTMorphingLabel {
}

effectClosures["Sparkle\(phaseDisappear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

return LTCharacterLimbo(
char: char,
Expand All @@ -101,7 +101,7 @@ extension LTMorphingLabel {
}

effectClosures["Sparkle\(phaseAppear)"] = {
(char:Character, index: Int, progress: Float) in
char, index, progress in

if char != " " {
let rect = self.newRects[index]
Expand Down
14 changes: 8 additions & 6 deletions LTMorphingLabel/LTMorphingLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typealias LTMorphingSkipFramesClosure =


// MARK: - LTMorphingLabel
@IBDesignable public class LTMorphingLabel : UILabel {
@IBDesignable public class LTMorphingLabel: UILabel {

@IBInspectable public var morphingProgress: Float = 0.0
@IBInspectable public var morphingDuration: Float = 0.6
Expand Down Expand Up @@ -95,7 +95,7 @@ typealias LTMorphingSkipFramesClosure =
let presentingInIB = false
#endif

override public var text:String! {
override public var text: String! {
get {
return super.text
}
Expand Down Expand Up @@ -136,7 +136,7 @@ typealias LTMorphingSkipFramesClosure =
newRects = rectsOfEachCharacter(text ?? "", withFont: font)
}

override public var bounds:CGRect {
override public var bounds: CGRect {
get {
return super.bounds
}
Expand All @@ -146,7 +146,7 @@ typealias LTMorphingSkipFramesClosure =
}
}

override public var frame:CGRect {
override public var frame: CGRect {
get {
return super.frame
}
Expand Down Expand Up @@ -211,7 +211,7 @@ extension LTMorphingLabel {

// Could be enhanced by kerning text:
// http://stackoverflow.com/questions/21443625/core-text-calculate-letter-frame-in-ios
func rectsOfEachCharacter(textToDraw:String, withFont font:UIFont) -> [CGRect] {
func rectsOfEachCharacter(textToDraw: String, withFont font: UIFont) -> [CGRect] {
var charRects = [CGRect]()
var leftOffset: CGFloat = 0.0

Expand Down Expand Up @@ -391,6 +391,7 @@ extension LTMorphingLabel {

return limbo
}

}


Expand Down Expand Up @@ -418,7 +419,7 @@ extension LTMorphingLabel {
}

for charLimbo in limboOfCharacters() {
let charRect:CGRect = charLimbo.rect
let charRect = charLimbo.rect

let willAvoidDefaultDrawing: Bool = {
if let closure = drawingClosures[
Expand All @@ -440,4 +441,5 @@ extension LTMorphingLabel {
}
}
}

}
4 changes: 2 additions & 2 deletions LTMorphingLabel/NSString+LTMorphingLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import Foundation


public enum LTCharacterDiffType : Int, CustomDebugStringConvertible {
public enum LTCharacterDiffType: Int, CustomDebugStringConvertible {

case Same = 0
case Add = 1
Expand Down Expand Up @@ -57,7 +57,7 @@ public enum LTCharacterDiffType : Int, CustomDebugStringConvertible {
}


public struct LTCharacterDiffResult : CustomDebugStringConvertible {
public struct LTCharacterDiffResult: CustomDebugStringConvertible {

public var diffType: LTCharacterDiffType = .Add
public var moveOffset: Int = 0
Expand Down
19 changes: 17 additions & 2 deletions LTMorphingLabelDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@
D74AD96B195171E7009A2ACD /* Frameworks */,
D74AD96C195171E7009A2ACD /* Resources */,
D7D4B0371A5E87D50087F83D /* Embed Frameworks */,
D7E30A621C28449F00A708CF /* SwiftLint */,
D7E30A631C2844B000A708CF /* Tailor */,
);
buildRules = (
);
Expand Down Expand Up @@ -305,7 +307,6 @@
D7D4B01B1A5E87D50087F83D /* Frameworks */,
D7D4B01C1A5E87D50087F83D /* Headers */,
D7D4B01D1A5E87D50087F83D /* Resources */,
D7CA19C31C17CE9A00F2EFDB /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -394,7 +395,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
D7CA19C31C17CE9A00F2EFDB /* SwiftLint */ = {
D7E30A621C28449F00A708CF /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -408,6 +409,20 @@
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"SwiftLint does not exist, download from https://github.com/realm/SwiftLint\"\nfi";
};
D7E30A631C2844B000A708CF /* Tailor */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = Tailor;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if hash tailor 2>/dev/null; then\ntailor ${SRCROOT}/LTMorphingLabel/ --except=trailing-whitespace,lower-camel-case\nelse\necho \"warning: Please install Tailor from https://tailor.sh\"\nfi";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
Binary file not shown.

0 comments on commit 13a73ec

Please sign in to comment.