Skip to content

Commit 2a4cd58

Browse files
author
Alejandro
committed
Readme updated, PDFImageView & PDFImageRenderer updated
1 parent 624f795 commit 2a4cd58

File tree

9 files changed

+280
-260
lines changed

9 files changed

+280
-260
lines changed

Examples/Examples-macOs/StringSample.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ class StringSample: NSView {
5353

5454
//Start animation loop
5555
swapText()
56+
57+
//Use timeline to repeat forever.
58+
Timeline(
59+
//Create tween with StringAim target and animate interpolation.
60+
Tween(target:stringAim)
61+
.delay(0.5)
62+
.duration(0.5)
63+
.ease(.none)
64+
.keys(to:[\StringAim.interpolation : 1.0])
65+
.onComplete { self.swapText() }
66+
)
67+
.mode(.loop)
68+
.play()
5669
}
5770

5871
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
@@ -62,19 +75,7 @@ class StringSample: NSView {
6275
stringAim.from = stringAim.to
6376
stringAim.to = changeText(oldText:stringAim.to)
6477
stringAim.interpolation = 0.0
65-
66-
//Create tween with StringAim target and animate interpolation.
67-
Tween(target: stringAim,
68-
duration: 0.5,
69-
ease: .none,
70-
delay: 0.0,
71-
to: [\StringAim.interpolation : 1.0],
72-
completion: {
73-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
74-
self.swapText()
75-
})
76-
}).play()
77-
}
78+
}
7879

7980
func changeText(oldText:String) -> String
8081
{

Examples/Examples.xcodeproj/project.pbxproj

Lines changed: 204 additions & 204 deletions
Large diffs are not rendered by default.

Examples/Examples/AppDelegate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ protocol FreezeProtocol {
1515
func warm()
1616
}
1717

18+
1819
@UIApplicationMain
1920
class AppDelegate: UIResponder, UIApplicationDelegate {
2021

@@ -23,6 +24,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2324
let view = UIView(frame:UIScreen.main.bounds)
2425
var timeline: Timeline = Timeline()
2526

27+
func kpCollect<UIView>(_ kp:[PartialKeyPath<UIView>:Any]... ){
28+
29+
}
30+
2631
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
2732
{
2833
viewController.view.frame = UIScreen.main.bounds

Examples/Examples/SimpleTween.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ class SimpleTween:UIView, FreezeProtocol
5050
.ease(.inOutCubic)
5151
.keys(to:
5252
[\UIView.alpha:1.0,
53-
\UIView.frame:CGRect(x:20.0, y:20.0, width:UIScreen.main.bounds.width - 40, height:UIScreen.main.bounds.width - 40),
53+
\UIView.frame:CGRect(x:20.0,
54+
y:20.0,
55+
width:UIScreen.main.bounds.width - 40,
56+
height:UIScreen.main.bounds.width - 40),
5457
//NOTE:This property is an optional, add ! to keypath.
5558
\UIView.backgroundColor!:UIColor.red])
5659
.onComplete { print("Tween complete") }

README.md

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ Tween(target:myView)
2222
.ease(.inOutCubic)
2323
.keys(to:
2424
[\UIView.alpha:1.0,
25-
\UIView.frame:CGRect(x:20.0, y:20.0, width:UIScreen.main.bounds.width - 40, height:UIScreen.main.bounds.width - 40),
26-
//NOTE:This property is an optional, add ! to keypath.
27-
\UIView.backgroundColor!:UIColor.red])
25+
\UIView.frame:CGRect(x:20.0, y:20.0, width:250, height:250),
26+
\UIView.backgroundColor!:UIColor.red])//NOTE:This property is an optional, add ! to keypath.
2827
.onComplete { print("Tween complete") }
2928
.after()//Creates a new tween after with same target and properties.
3029
.duration(0.75)
3130
.ease(.outBounce)
3231
.keys(to: [\UIView.alpha:0.25,
33-
\UIView.frame:CGRect(x:20.0, y:20.0, width:100.0, height:100.0),
32+
\UIView.frame:CGRect(x:20.0, y:20.0, width:50.0, height:50.0),
3433
\UIView.backgroundColor!:UIColor.blue])
3534
.play()
3635
```
@@ -45,16 +44,15 @@ Timeline(
4544
//Tween 1
4645
Tween(target: myView)
4746
.ease(.inOutQuad)
48-
.keys(to:[\UIView.center : self.frame.origin])
47+
.keys(to:[\UIView.center : frame.origin])
4948
.onStart {
5049
self.myView.flipX(inverted: true)
5150
}
5251
.onComplete { print("Tween 1 complete") },
5352

5453
//Tween 2
5554
Tween(target: myView)
56-
.after()
57-
.keys(to:[\UIView.center : self.center])
55+
.keys(to:[\UIView.center : .center])
5856
.onStart {
5957
self.myView.flipY()
6058
}
@@ -121,6 +119,11 @@ Tweener.addType(
121119

122120
Now, you can animate a 'Vector3' Type object.
123121

122+
```swift
123+
Tween(target:myInstance)
124+
.keys(to:[\SomeType.point3d:Vector3(x:100, y:200, z:-100)])
125+
```
126+
124127
### MacOS support
125128

126129
This version includes macOS support and samples.
@@ -138,7 +141,7 @@ $ gem install cocoapods
138141

139142
Now, add Tweener to your Podfile
140143
```
141-
pod 'Tweener', '~> 2.0'
144+
pod 'Tweener', '~> 2.0.1'
142145
```
143146

144147
To install dependencies run this command:
@@ -156,7 +159,7 @@ $ brew install carthage
156159

157160
Now, add Tweener to your Cartfile
158161
```
159-
github "alexrvarela/SwiftTweener" ~> 2.0
162+
github "alexrvarela/SwiftTweener" ~> 2.0.1
160163
```
161164

162165
To install dependencies run this command:
@@ -172,7 +175,7 @@ To install, add dependencies to your Package.swift
172175

173176
```
174177
dependencies: [
175-
.package(url: "https://github.com/alexrvarela/SwiftTweener.git", .upToNextMajor(from: "2.0"))
178+
.package(url: "https://github.com/alexrvarela/SwiftTweener.git", .upToNextMajor(from: "2.0.1"))
176179
]
177180
```
178181

@@ -307,11 +310,11 @@ This engine is based on Robert Penner's [Easing equations](http://robertpenner.c
307310
To create a custom easing equation:
308311
```swift
309312
extension Ease{
310-
public static let custom : Equation = { (t, b, c, d) in
313+
public static let custom = Ease(equation:{ (t, b, c, d) in
311314
//Play with code here!
312-
if t < d/2 {return .inBack(t*2, b, c/2, d)}
313-
return .outElastic((t*2)-d, b+c/2, c/2, d)
314-
}
315+
if t < d/2 {return Ease.inBack.equation(t*2, b, c/2, d)}
316+
return Ease.outElastic.equation((t*2)-d, b+c/2, c/2, d)
317+
})
315318
}
316319
```
317320

@@ -333,22 +336,22 @@ It depends on what do you want, a Tween only animates “to” desired value tak
333336
Timeline stores “from” and “to” values of each Tween, contains a collection of reusable Tweens, to create Timeline and add Tweens use this code:
334337

335338
```swift
336-
let myTimeline:Timeline = Timeline()
337-
myTimeline.add(myTween)
338-
myTimeline.play()
339+
let myTimeline = Timeline()
340+
.add(myTween)
341+
.play()
339342
```
340343

341344
You can interact with Timeline play modes, the default value is Play once, it stops when finished, to change Tmeline play mode:
342345

343346
Loop, repeat forever
344347
```swift
345-
myTimeline.playMode = .loop
348+
myTimeline.playMode(.loop)
346349
```
347350
![Loop](https://raw.githubusercontent.com/alexrvarela/SwiftTweener/master/Gifs/timeline-play.gif)
348351

349352
Ping Pong, forward and reverse
350353
```swift
351-
myTimeline.playMode = .pingPong
354+
myTimeline.playMode(.pingPong)
352355
```
353356

354357
To remove a Timeline from Engine simply call stop().
@@ -382,7 +385,7 @@ addSubview(myInspector)
382385

383386
### PDFImageView
384387

385-
Cut with the image dependency and easily import your vector assets using PDFImageView, forget to export to SVG and other formats iOs offers native support for PDF with CoreGraphics, this class simply renders one pdf inside a UIImageView.
388+
Cut with the image dependency and easily import your vector assets using PDFImageView, forget to export to SVG and other formats iOs offers native support for PDF with CoreGraphics, this class simply renders one pdf inside a UIImageView
386389

387390
To load your asset named "bee.pdf" from App bundle:
388391

@@ -479,15 +482,25 @@ Animate text transitions
479482

480483
```swift
481484
//Create string aim
482-
let myStringAim = StringAim(target:myUILabel, keyPath:\UILabel.text)
483-
myStringAim.from = "hello"
484-
myStringAim.to = "hola"
485+
let stringAim = StringAim(target:myUILabel, keyPath:\UILabel.text)
486+
stringAim.from = "hello"
487+
stringAim.to = "hola"
485488

486489
//Set initial interpolation
487-
myStringAim.interpolation = 0.0
490+
stringAim.interpolation = 0.0
488491

489-
//Animate interpolation
490-
Tween(target: myStringAim, duration: 0.5, to: [\StringAim.interpolation : 1.0]).play()
492+
//Animate, usese timeline to repeat forever.
493+
Timeline(
494+
//Create tween with StringAim target and animate interpolation.
495+
Tween(target:stringAim)
496+
.delay(0.5)
497+
.duration(0.5)
498+
.ease(.none)
499+
.keys(to:[\StringAim.interpolation : 1.0])
500+
.onComplete { self.swapText() }
501+
)
502+
.mode(.loop)
503+
.play()
491504
```
492505

493506
Play with everything, combine different types of Aim:

Source/PDFImageRender.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
import UIKit
1212

1313
/// Renders a PDF document in to a UIImage.
14-
class PDFImageRender
14+
open class PDFImageRender
1515
{
16-
var data: Data?
17-
var document: CGPDFDocument?
18-
19-
var pageCount: Int
16+
//public static var staticBundle:Bundle?
17+
18+
public var data: Data?
19+
public var document: CGPDFDocument?
20+
public var pageCount: Int
2021
{
2122
if self.document == nil{return 0}
2223
else {return (self.document?.numberOfPages)!}
2324
}
2425

25-
func setPDFData(data:Data?)
26+
public func setPDFData(data:Data?)
2627
{
2728
if (data != nil)
2829
{
@@ -37,25 +38,25 @@ class PDFImageRender
3738
}
3839
}
3940

40-
func loadFromBundle(filename: String)
41+
public func loadFromBundle(filename: String)
4142
{
4243
let path:String = Bundle.main.path(forResource: filename, ofType: ".pdf")!
4344
loadFile(path: path)
4445
}
4546

46-
func loadFile(path:String)
47+
public func loadFile(path:String)
4748
{
4849
setPDFData(data: FileManager.default.contents(atPath: path))
4950
}
5051

5152
/// Get current page size
52-
func getPageSize(page:Int) ->CGSize
53+
public func getPageSize(page:Int) ->CGSize
5354
{
5455
if self.data == nil {return CGSize.zero}
5556
return self.document!.page(at: page)!.getBoxRect(.cropBox).size
5657
}
5758
/// Render page
58-
func renderPage(page: Int, scale:Double) -> UIImage?
59+
public func renderPage(page: Int, scale:Double) -> UIImage?
5960
{
6061
if self.document == nil {return nil}
6162

Source/PDFImageView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#if os(iOS)
1010
import UIKit
1111
/// Creates a UIImageView which renders and displays a PDF document's CGImage.
12-
public class PDFImageView : UIImageView
12+
open class PDFImageView : UIImageView
1313
{
14-
var pdf:PDFImageRender = PDFImageRender()
14+
public let pdf:PDFImageRender = PDFImageRender()
1515

1616
private var _scale: Double = 1.0
1717

@@ -106,7 +106,7 @@ public class PDFImageView : UIImageView
106106
}
107107

108108
/// Refresh pdf's image.
109-
func updateImage()
109+
public func updateImage()
110110
{
111111
if self.pdf.document != nil
112112
{

Tweener.framework.zip

122 KB
Binary file not shown.

Tweener.xcodeproj/project.pbxproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
FA84B19524F1EDB2004A50B2 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = FA84B19124F1EDB2004A50B2 /* README.md */; };
6969
FA84B19624F1EDB2004A50B2 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = FA84B19224F1EDB2004A50B2 /* LICENSE */; };
7070
FA84B19724F1EDB2004A50B2 /* Tweener.podspec in Resources */ = {isa = PBXBuildFile; fileRef = FA84B19324F1EDB2004A50B2 /* Tweener.podspec */; };
71-
FADF0194251A735100EAF4E3 /* PathSample.swift in Sources */ = {isa = PBXBuildFile; fileRef = FADF018F251A735100EAF4E3 /* PathSample.swift */; };
7271
/* End PBXBuildFile section */
7372

7473
/* Begin PBXFileReference section */
@@ -147,7 +146,6 @@
147146
isa = PBXGroup;
148147
children = (
149148
FA84B19224F1EDB2004A50B2 /* LICENSE */,
150-
FADF018F251A735100EAF4E3 /* PathSample.swift */,
151149
FA84B1A024F2DAD4004A50B2 /* Package.swift */,
152150
FA84B19124F1EDB2004A50B2 /* README.md */,
153151
FA84B19324F1EDB2004A50B2 /* Tweener.podspec */,
@@ -492,7 +490,6 @@
492490
FA7170CE24E4A4870001965F /* RotationAim.swift in Sources */,
493491
FA7170CF24E4A4870001965F /* ArcAim.swift in Sources */,
494492
FA7170D024E4A4870001965F /* PathAim.swift in Sources */,
495-
FADF0194251A735100EAF4E3 /* PathSample.swift in Sources */,
496493
FA7170D124E4A4870001965F /* StringAim.swift in Sources */,
497494
FA7170D224E4A4870001965F /* BezierUtils.swift in Sources */,
498495
FA7170D324E4A4870001965F /* CGPathUtils.swift in Sources */,

0 commit comments

Comments
 (0)