Skip to content

Commit

Permalink
Merge pull request #3 from cruisediary/feature/support-direction
Browse files Browse the repository at this point in the history
Support animation direction
  • Loading branch information
cruisediary committed May 7, 2017
2 parents 6d608a3 + d704f61 commit 6739c19
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 12 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Expand Up @@ -2,13 +2,17 @@
# * http://www.objc.io/issue-6/travis-ci.html
# * https://github.com/supermarin/xcpretty#usage

osx_image: xcode7.3
osx_image: xcode8
language: objective-c
xcode-project: Pastel.xcworkspace
xcode_scheme: Pastel
xcode_sdk: iphonesimulator8.4
# cache: cocoapods
# podfile: Example/Podfile
# before_install:
# - gem install cocoapods # Since Travis is not always on latest version
# - pod install --project-directory=Example
script:
- set -o pipefail && xcodebuild test -workspace Example/Pastel.xcworkspace -scheme Pastel-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
- pod lib lint
- xcodebuild -scheme 'Pastel' -sdk iphonesimulator CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO test | xcpretty -c

17 changes: 17 additions & 0 deletions Example/Pastel/ViewController.swift
Expand Up @@ -21,6 +21,23 @@ class ViewController: UIViewController {
super.viewDidLoad()

let pastelView = PastelView(frame: view.bounds)

// Custom Direction
pastelView.startPoint = .bottomLeft
pastelView.endPoint = .topRight

// Custom Duration
pastelView.animationDuration = 3.0

// Custom Color
pastelView.setColors(colors: [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])

pastelView.startAnimation()
view.insertSubview(pastelView, at: 0)
// Do any additional setup after loading the view, typically from a nib.
Expand Down
2 changes: 1 addition & 1 deletion Pastel.podspec
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Pastel'
s.version = '0.1.2'
s.version = '0.2.0'
s.summary = 'Instagram like gradient background animation'

# This description is used to generate tags and improve search results.
Expand Down
42 changes: 37 additions & 5 deletions Pastel/Classes/PastelView.swift
Expand Up @@ -10,15 +10,47 @@ import UIKit

public class PastelView: UIView {

struct Animation {
private struct Animation {
static let keyPath = "colors"
static let key = "ColorChange"
}

let gradient = CAGradientLayer()
var currentGradient: Int = 0
public enum Point {
case left
case top
case right
case bottom
case topLeft
case topRight
case bottomLeft
case bottomRight
case custom(position: CGPoint)

var point: CGPoint {
switch self {
case .left: return CGPoint(x: 0.0, y: 0.5)
case .top: return CGPoint(x: 0.5, y: 0.0)
case .right: return CGPoint(x: 1.0, y: 0.5)
case .bottom: return CGPoint(x: 0.5, y: 1.0)
case .topLeft: return CGPoint(x: 0.0, y: 0.0)
case .topRight: return CGPoint(x: 1.0, y: 0.0)
case .bottomLeft: return CGPoint(x: 0.0, y: 1.0)
case .bottomRight: return CGPoint(x: 1.0, y: 1.0)
case .custom(let point):
return point
}
}
}

// Custom Direction
open var startPoint: Point = .topRight
open var endPoint: Point = .bottomLeft

// Custom Duration
open var animationDuration: TimeInterval = 5.0

fileprivate let gradient = CAGradientLayer()
private var currentGradient: Int = 0
private var colors: [UIColor] = [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
Expand Down Expand Up @@ -55,8 +87,8 @@ public class PastelView: UIView {
fileprivate func setup() {
gradient.frame = bounds
gradient.colors = currentGradientSet()
gradient.startPoint = CGPoint(x:0, y:1)
gradient.endPoint = CGPoint(x:1, y:0)
gradient.startPoint = startPoint.point
gradient.endPoint = endPoint.point
gradient.drawsAsynchronously = true

layer.insertSublayer(gradient, at: 0)
Expand Down
23 changes: 19 additions & 4 deletions README.md
@@ -1,7 +1,8 @@
# Pastel
Instagram like Gradient background animation

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

let pastelView = PastelView(frame: view.bounds)
pastelView.setColors(colors: [.blue, .white, .black]) // set custom colors
pastelView.addColor(color: .red)
pastelView.animationDuration = 2.5

// Custom Direction
pastelView.startPoint = .bottomLeft
pastelView.endPoint = .topRight

// Custom Duration
pastelView.animationDuration = 3.0

// Custom Color
pastelView.setColors(colors: [UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1.0),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1.0),
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1.0),
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1.0),
UIColor(red: 32/255, green: 158/255, blue: 255/255, alpha: 1.0),
UIColor(red: 90/255, green: 120/255, blue: 127/255, alpha: 1.0),
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1.0)])

pastelView.startAnimation()
view.insertSubview(pastelView, at: 0)
}
Expand Down

0 comments on commit 6739c19

Please sign in to comment.