Skip to content

Commit 6739c19

Browse files
authored
Merge pull request #3 from cruisediary/feature/support-direction
Support animation direction
2 parents 6d608a3 + d704f61 commit 6739c19

File tree

5 files changed

+80
-12
lines changed

5 files changed

+80
-12
lines changed

.travis.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
# * http://www.objc.io/issue-6/travis-ci.html
33
# * https://github.com/supermarin/xcpretty#usage
44

5-
osx_image: xcode7.3
5+
osx_image: xcode8
66
language: objective-c
7+
xcode-project: Pastel.xcworkspace
8+
xcode_scheme: Pastel
9+
xcode_sdk: iphonesimulator8.4
710
# cache: cocoapods
811
# podfile: Example/Podfile
912
# before_install:
1013
# - gem install cocoapods # Since Travis is not always on latest version
1114
# - pod install --project-directory=Example
1215
script:
13-
- set -o pipefail && xcodebuild test -workspace Example/Pastel.xcworkspace -scheme Pastel-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
1416
- pod lib lint
17+
- xcodebuild -scheme 'Pastel' -sdk iphonesimulator CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO test | xcpretty -c
18+

Example/Pastel/ViewController.swift

+17
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ class ViewController: UIViewController {
2121
super.viewDidLoad()
2222

2323
let pastelView = PastelView(frame: view.bounds)
24+
25+
// Custom Direction
26+
pastelView.startPoint = .bottomLeft
27+
pastelView.endPoint = .topRight
28+
29+
// Custom Duration
30+
pastelView.animationDuration = 3.0
31+
32+
// Custom Color
33+
pastelView.setColors(colors: [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
34+
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
35+
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
36+
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
37+
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
38+
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
39+
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])
40+
2441
pastelView.startAnimation()
2542
view.insertSubview(pastelView, at: 0)
2643
// Do any additional setup after loading the view, typically from a nib.

Pastel.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'Pastel'
11-
s.version = '0.1.2'
11+
s.version = '0.2.0'
1212
s.summary = 'Instagram like gradient background animation'
1313

1414
# This description is used to generate tags and improve search results.

Pastel/Classes/PastelView.swift

+37-5
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,47 @@ import UIKit
1010

1111
public class PastelView: UIView {
1212

13-
struct Animation {
13+
private struct Animation {
1414
static let keyPath = "colors"
1515
static let key = "ColorChange"
1616
}
1717

18-
let gradient = CAGradientLayer()
19-
var currentGradient: Int = 0
18+
public enum Point {
19+
case left
20+
case top
21+
case right
22+
case bottom
23+
case topLeft
24+
case topRight
25+
case bottomLeft
26+
case bottomRight
27+
case custom(position: CGPoint)
28+
29+
var point: CGPoint {
30+
switch self {
31+
case .left: return CGPoint(x: 0.0, y: 0.5)
32+
case .top: return CGPoint(x: 0.5, y: 0.0)
33+
case .right: return CGPoint(x: 1.0, y: 0.5)
34+
case .bottom: return CGPoint(x: 0.5, y: 1.0)
35+
case .topLeft: return CGPoint(x: 0.0, y: 0.0)
36+
case .topRight: return CGPoint(x: 1.0, y: 0.0)
37+
case .bottomLeft: return CGPoint(x: 0.0, y: 1.0)
38+
case .bottomRight: return CGPoint(x: 1.0, y: 1.0)
39+
case .custom(let point):
40+
return point
41+
}
42+
}
43+
}
44+
45+
// Custom Direction
46+
open var startPoint: Point = .topRight
47+
open var endPoint: Point = .bottomLeft
48+
49+
// Custom Duration
2050
open var animationDuration: TimeInterval = 5.0
2151

52+
fileprivate let gradient = CAGradientLayer()
53+
private var currentGradient: Int = 0
2254
private var colors: [UIColor] = [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
2355
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
2456
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
@@ -55,8 +87,8 @@ public class PastelView: UIView {
5587
fileprivate func setup() {
5688
gradient.frame = bounds
5789
gradient.colors = currentGradientSet()
58-
gradient.startPoint = CGPoint(x:0, y:1)
59-
gradient.endPoint = CGPoint(x:1, y:0)
90+
gradient.startPoint = startPoint.point
91+
gradient.endPoint = endPoint.point
6092
gradient.drawsAsynchronously = true
6193

6294
layer.insertSublayer(gradient, at: 0)

README.md

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Pastel
22
Instagram like Gradient background animation
33

4-
[![CI Status](http://img.shields.io/travis/cruz/Pastel.svg?style=flat)](https://travis-ci.org/cruz/Pastel)
4+
![Swift](https://img.shields.io/badge/Swift-3.0-orange.svg)
5+
[![CI Status](http://img.shields.io/travis/cruz/Pastel.svg?style=flat)](https://travis-ci.org/cruisediary/Pastel)
56
[![Version](https://img.shields.io/cocoapods/v/Pastel.svg?style=flat)](http://cocoapods.org/pods/Pastel)
67
[![License](https://img.shields.io/cocoapods/l/Pastel.svg?style=flat)](http://cocoapods.org/pods/Pastel)
78
[![Platform](https://img.shields.io/cocoapods/p/Pastel.svg?style=flat)](http://cocoapods.org/pods/Pastel)
@@ -16,9 +17,23 @@ override func viewDidLoad() {
1617
super.viewDidLoad()
1718

1819
let pastelView = PastelView(frame: view.bounds)
19-
pastelView.setColors(colors: [.blue, .white, .black]) // set custom colors
20-
pastelView.addColor(color: .red)
21-
pastelView.animationDuration = 2.5
20+
21+
// Custom Direction
22+
pastelView.startPoint = .bottomLeft
23+
pastelView.endPoint = .topRight
24+
25+
// Custom Duration
26+
pastelView.animationDuration = 3.0
27+
28+
// Custom Color
29+
pastelView.setColors(colors: [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
30+
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
31+
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
32+
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
33+
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
34+
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
35+
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])
36+
2237
pastelView.startAnimation()
2338
view.insertSubview(pastelView, at: 0)
2439
}

0 commit comments

Comments
 (0)