🎨 Gradient animation effect like Instagram

Overview

Pastel

🎨 Gradient animation effect like Instagram

Awesome Swift CI Status Version License Platform Carthage compatible

pastel_01.gif pastel_02.gif pastel_03.gif

Example

override func viewDidLoad() {
    super.viewDidLoad()

    let pastelView = PastelView(frame: view.bounds)

    // Custom Direction
    pastelView.startPastelPoint = .bottomLeft
    pastelView.endPastelPoint = .topRight

    // Custom Duration
    pastelView.animationDuration = 3.0

    // Custom Color
    pastelView.setColors([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)
}

🎨 Customize Gradient Colors

Designed by Alexander Zaytsev, https://dribbble.com/anwaltzzz

Gradient.png

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Pastel is written in Swift 3+. iOS 8.0+ Required

Installation

Pastel is available through CocoaPods or Carthage.

Cocoapods

pod "Pastel"

Carthage

github "cruisediary/Pastel" ~> 0.6.0

Example

  • Passcode: A simple Passcode application using RxSwift, ReactorKit, IGListKit with Pastel

Awesome

  • awesome-swift - A collaborative list of awesome Swift libraries and resources. Feel free to contribute!
  • awesome-gradient - 🌈 A curated list of awesome Gradient frameworks, libraries and software and resources

Author

cruz, [email protected]

Thanks

Many thanks to the contributors of this project.

License

Pastel is available under the MIT license. See the LICENSE file for more info.

Comments
  • Restore state after application enters background.

    Restore state after application enters background.

    Wherever someone leaves my app and lets it go into the background, when they then later open the app, the gradient is no longer cycling.

    Is there away to restore the state the gradient was in before being sent to background?

    thank you.

    I think I should be able to do it with func applicationDidBecomeActive(_ application: UIApplication) { but I don't know how

    opened by iambenmitchell 3
  • SPM Support + Files organisation

    SPM Support + Files organisation

    @cruisediary , I have modified lib with SPM support following way:

    • File reorganisation (Sources, Tests folders)
    • Package.swift file
    • PodSpec file update
    opened by ace4seven 2
  • changed build settings and removed '.gitkeep'

    changed build settings and removed '.gitkeep'

    When I use pastel through Carthage, I got the following log.

    /usr/bin/xcrun xcodebuild -project /Users/minjunju/Desktop/Cart/Carthage/Checkouts/Pastel/Pastel.xcodeproj -scheme Pastel -configuration Release -derivedDataPath /Users/minjunju/Library/Caches/org.carthage.CarthageKit/DerivedData/10.0_10A255/Pastel/0.5.1 -sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive -archivePath /var/folders/lm/f53m_74j4ns1xhzfykbfrw0m0000gp/T/Pastel SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO STRIP_INSTALLED_PRODUCT=NO (launched in /Users/minjunju/Desktop/Cart/Carthage/Checkouts/Pastel)User defaults from command line:
        IDEArchivePathOverride = /var/folders/lm/f53m_74j4ns1xhzfykbfrw0m0000gp/T/Pastel
        IDEDerivedDataPathOverride = /Users/minjunju/Library/Caches/org.carthage.CarthageKit/DerivedData/10.0_10A255/Pastel/0.5.1
    
    Build settings from command line:
        CARTHAGE = YES
        CLANG_ENABLE_CODE_COVERAGE = NO
        CODE_SIGN_IDENTITY = 
        CODE_SIGNING_REQUIRED = NO
        GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO
        ONLY_ACTIVE_ARCH = NO
        SDKROOT = iphoneos12.0
        SKIP_INSTALL = YES
        STRIP_INSTALLED_PRODUCT = NO
    
    note: Using new build system
    note: Planning build
    note: Constructing build description
    Build system information
    warning: The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "Pastel" target. (in target 'Pastel')
    
    Build system information
    warning: The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "Pastel" target. (in target 'Pastel')
    
    Build system information
    warning: duplicate output file '/Users/minjunju/Library/Caches/org.carthage.CarthageKit/DerivedData/10.0_10A255/Pastel/0.5.1/Build/Intermediates.noindex/ArchiveIntermediates/Pastel/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Pastel.framework/.gitkeep' on task: CpResource /Users/minjunju/Desktop/Cart/Carthage/Checkouts/Pastel/Pastel/Classes/.gitkeep /Users/minjunju/Library/Caches/org.carthage.CarthageKit/DerivedData/10.0_10A255/Pastel/0.5.1/Build/Intermediates.noindex/ArchiveIntermediates/Pastel/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Pastel.framework/.gitkeep (in target 'Pastel')
    
    Build system information
    error: Multiple commands produce '/Users/minjunju/Library/Caches/org.carthage.CarthageKit/DerivedData/10.0_10A255/Pastel/0.5.1/Build/Intermediates.noindex/ArchiveIntermediates/Pastel/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Pastel.framework/.gitkeep':
    1) Target 'Pastel' (project 'Pastel') has copy command from '/Users/minjunju/Desktop/Cart/Carthage/Checkouts/Pastel/Pastel/Assets/.gitkeep' to '/Users/minjunju/Library/Caches/org.carthage.CarthageKit/DerivedData/10.0_10A255/Pastel/0.5.1/Build/Intermediates.noindex/ArchiveIntermediates/Pastel/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Pastel.framework/.gitkeep'
    2) Target 'Pastel' (project 'Pastel') has copy command from '/Users/minjunju/Desktop/Cart/Carthage/Checkouts/Pastel/Pastel/Classes/.gitkeep' to '/Users/minjunju/Library/Caches/org.carthage.CarthageKit/DerivedData/10.0_10A255/Pastel/0.5.1/Build/Intermediates.noindex/ArchiveIntermediates/Pastel/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Pastel.framework/.gitkeep'
    
    ** ARCHIVE FAILED **`
    

    I think a problem because of'.gitkeep' exists. so I had deleted the .gitkeep in the Classes folder.

    In addition, I don't know a reason that whether you intend to set swift 3 @objc inference to 'on'. I have changed it to default because of proposals

    Please review myPR. thank you

    opened by devmjun 2
  • Use of unresolved identifier 'kCAFillModeForwards'

    Use of unresolved identifier 'kCAFillModeForwards'

    Constant has been removed in favor of a forwards property on the CAMediaTimingFillMode type. Solution has been tested on Xcode Version 10.0 beta 2 with Swift 4.2 and a project build for iOS 12.

    opened by julienwidmer 2
  • Pastelview does not cover 100% of screen width on iphone 6 plus

    Pastelview does not cover 100% of screen width on iphone 6 plus

    I added a uiview using storyboard and gave it a class of PastelView

    Autolayout contraints: Top space to superview: 0 Trailing/leading space to superview: 0 Height: 45

    More or less a uiview that is 45px high and hugs the top/left/right sides of my view.

    ViewdidLoad:

    self.testview.startPoint = .topRight
    self.testview.endPoint = .bottomLeft
    self.testview.animationDuration = 3.0
    self.testview.setColors(colors: [UIColor(red:0.99, green:0.19, blue:0.35, alpha:1.0),
                                                          UIColor(red:1.00, green:0.37, blue:0.57, alpha:1.0)])
    self.testview.startAnimation()
    

    When I run the simulator or test it on a real iphone 5 device everything looks fine, but when I run a iphone 6 plus or test it on a real iphone 6 plus device I can see that the gradient view doesnt cover the whole width, it gets to short on the right side:

    screen shot 2017-06-01 at 22 19 01

    The gradient animation still works but it doesnt cover 100% of the width.

    opened by kiwo12345 2
  • Use Swift 5.0

    Use Swift 5.0

    This PR migrates the project to use Swift 5.0 by default. No source changes were necessary, so the project should still build with Swift 4.2 if necessary.

    opened by agisboye 1
  • Implement PastelLayer

    Implement PastelLayer

    I wanted to use PastelView with AVFoundation because I wanted to add some nice gradient effects into my video-editing application. A small issue with AVFoundation is that it works only with CALayer instances and it doesn't allow UIKit controls, so I'm basically stuck with CALayer and can't use PastelView.

    So I took PastelView and created a PastelLayer, a CAGradientLayer's subclass, which does almost everything that PastelView can.

    class PastelLayer: CAGradientLayer, CAAnimationDelegate {
        private struct Animation {
            static let keyPath = "colors"
            static let key = "ColorChange"
        }
        
        var animationDuration: TimeInterval = 5.0
        var animationBeginTime: TimeInterval?
        var gradientColors: [UIColor] = [#colorLiteral(red: 0.6117647059, green: 0.1529411765, blue: 0.6901960784, alpha: 1), #colorLiteral(red: 1, green: 0.2509803922, blue: 0.5058823529, alpha: 1), #colorLiteral(red: 0.4823529412, green: 0.1215686275, blue: 0.6352941176, alpha: 1), #colorLiteral(red: 0.1254901961, green: 0.2980392157, blue: 1, alpha: 1), #colorLiteral(red: 0.1254901961, green: 0.6196078431, blue: 1, alpha: 1), #colorLiteral(red: 0.3529411765, green: 0.4705882353, blue: 0.4980392157, alpha: 1), #colorLiteral(red: 0.2274509804, green: 1, blue: 0.8509803922, alpha: 1)]
        
        private var currentGradient: Int = 0
        
        override init() {
            super.init()
            startPoint = CGPoint(x: 0.0, y: 1.0)
            endPoint = CGPoint(x: 1.0, y: 0.0)
        }
        
        override init(layer: Any) {
            super.init(layer: layer)
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        func startAnimation() {
            removeAllAnimations()
            setup()
            animateGradient()
        }
        
        private func currentGradientSet() -> [CGColor] {
            guard gradientColors.count > 0 else { return [] }
            return [gradientColors[currentGradient % gradientColors.count].cgColor,
                    gradientColors[(currentGradient + 1) % gradientColors.count].cgColor]
        }
        
        private func setup() {
            colors = currentGradientSet()
            drawsAsynchronously = true
        }
        
        func animateGradient() {
            currentGradient += 1
            let animation = CABasicAnimation(keyPath: Animation.keyPath)
            animation.duration = animationDuration
            if let time = animationBeginTime {
                animation.beginTime = time
            }
            animation.toValue = currentGradientSet()
            animation.fillMode = .forwards
            animation.isRemovedOnCompletion = false
            animation.delegate = self
            add(animation, forKey: Animation.key)
        }
        
        override func removeFromSuperlayer() {
            removeAllAnimations()
            super.removeFromSuperlayer()
        }
        
        func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
            if flag {
                colors = currentGradientSet()
                animateGradient()
            }
        }
    }
    

    I find this subclass to be incredibly useful for my purposes, I suggest that we add this subclass to the project, and then PastelView will be a simple wrapper around this subclass. In fact, PastelView can use PastelLayer as its layerClass which would allow PastelView to interact with auto layout (although, I never tested it, but it should work just fine).

    class PastelView: UIView {
        override static var layerClass: AnyClass {
            return PastelLayer.self
        }
    }
    

    Downside of this approach is that PastelView would become a simple wrapper around PastelLayer and will have a lot of computed variables and functions that will just call similar function on PastelLayer, e.g.

    class PastelView: UIView {
        var endPoint: CGPoint {
            set {
                gradientLayer.endPoint = endPoint
            } get {
                return gradientLayer.endPoint
            }
        }
        
        private var gradientLayer: PastelLayer {
            return layer as! PastelLayer
        }
    }
    

    Anyway, I find this addition to be useful when working with CoreAnimation directly, and if you find this idea useful, I will be more than happy to make a PR.

    opened by xinatanil 1
  • modify class access control (public -> open)

    modify class access control (public -> open)

    I changed the access control from public to open in order to inherit and pre-set property values ​​inside.

    ex)

    class CustomPastelView: PastelView {
    ...
       func initialize() {
    // Custom Direction
        startPoint = .bottomLeft
        endPoint = .topRight
    
        // Custom Duration
        animationDuration = 3.0
    
        // Custom Color
        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)])
      }
    }
    
    opened by Kofktu 1
  • Making PastelView more Objc compatible.

    Making PastelView more Objc compatible.

    Currently PastelView is not fully objc compatible because of the Point enum.

    I made several changes to make it compatible and maintain the full original functionality:

    • Point enum renamed to PastelPoint and custom case with associated type removed.

    • startPoint and endPoint properties are now CGPoint allowing for setting custom points without enum

    • Added startPastelPoint and endPastelPoint properties to PastelView which will set the startPoint and endPoint CGPoint properties from their didSet methods.

    • Changed method definition for setColors and addColor for better readability when using. *not needed for the objc support.

    • Changed code in Readme to reflect changes.

    With these changes, PastelView is fully usable in objc out of the box.

    opened by kgellci 1
  • Update README.md

    Update README.md

    Also list Carthage as an installation option in the README.

    I think its better to just have the Carthage and Podfile examples there for the user to Cut & Paste.

    How does it look?

    opened by Nirma 1
  • Add Gradient 20 set

    Add Gradient 20 set

    from https://webgradients.com/

    case winterNeva
    case dustyGrass
    case temptingAzure
    case heavyRain
    case amyCrisp
    case meanFruit
    case deepBlue
    case ripeMalinka
    case cloudyKnoxville
    case malibuBeach
    case newLife
    case trueSunset
    case morpheusDen
    case rareWind
    case nearMoon
    case wildApple
    case saintPeterburg
    case ariellesSmile
    case plumPlate
    case everlastingSky
    case happyFisher
    
    opened by cruisediary 0
  • WORKAROUND: Animation stops when another view controller is presented

    WORKAROUND: Animation stops when another view controller is presented

    For those who are still having these issues, and looking for an approach to it, I highly recommend using Hero for the transition between view controllers instead of the default one.

    From the Hero documentation

    "It won't modify any of your views' states other than hiding them during the animation,"

    which really suitable for our case here since the previous view's just hiding, thus the transition doesn't interrupt the animation of the gradients at all.

    You can find HERO library through this link: https://github.com/HeroTransitions/Hero

    Happy coding everyone : )

    opened by VatanaChhorn 0
  • Animation stops if another view controller is presented

    Animation stops if another view controller is presented

    My controller includes a ImagePickerController, as soon as that displays, the background stops animating. Any ideas why? and how can i make it move again when the imagePicker dismisses

    opened by tapizquent 5
  • Carthage build failed

    Carthage build failed

    Environment

    Xcode 10 + Swift 4.2

    Carthage command:

    carthage update Pastel --platform ios --no-use-binaries
    

    Build output

    Build Failed Task failed with exit code 65: /usr/bin/xcrun xcodebuild -project /Users/lvjun/Desktop/StarOrder3-iOS/Carthage/Checkouts/Pastel/Pastel.xcodeproj -scheme Pastel -configuration Release -derivedDataPath /Users/lvjun/Library/Caches/org.carthage.CarthageKit/DerivedData/10.1_10B61/Pastel/0.5.1 -sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive -archivePath /var/folders/hl/__r3qrxd5_168lfx7v85xf3c0000gn/T/Pastel SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO STRIP_INSTALLED_PRODUCT=NO (launched in /Users/lvjun/Desktop/StarOrder3-iOS/Carthage/Checkouts/Pastel)

    This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/hl/__r3qrxd5_168lfx7v85xf3c0000gn/T/carthage-xcodebuild.c9ufBT.log

    opened by akring 1
  • Can't reset gradient view?

    Can't reset gradient view?

    I have a button in my app which has a "random gradient" functionality.

    How can I remove any existing gradient on the screen and replace it with a new one?

    I don't see any functionality in the api code which will allow us to set new gradients without removing the entire view and re-adding it to the screen.

    opened by patthehuman 0
Releases(0.6.0)
Owner
Cruz
🏄🏼 Open Source | iOS & Swift 📱+ ⛵️ engineer at @hyperconnect
Cruz
SYBlinkAnimationKit is a blink effect animation framework for iOS, written in Swift.

SYBlinkAnimationKit is a blink effect animation framework for iOS, written in Swift ?? Demo There are 5 types of animation for component. border borde

Shohei Yokoyama 126 Oct 28, 2021
Simple Interface Core Animation. Run type-safe animation sequencially or parallelly

Simple Interface Core Animation Sica can execute various animations sequentially or parallelly. Features Animation with duration and delay parallel /

CATS Open Source Softwares 1k Nov 10, 2022
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

null 28 Jan 8, 2023
Swiftui-animation-observer - Track SwiftUI animation progress and completion via callbacks

SwiftUI Animation Observer Track SwiftUI animation progress and completion via c

Gordan Glavaš 9 Nov 5, 2022
Bring life to CALayers with SpriteKit-like animation builders

Animo Bring life to CALayers with SpriteKit-like animation builders. Why use Animo? Because declaring CAAnimations (especially with CAAnimationGroups)

エウレカ 279 Dec 9, 2022
FloatingBubbles is a customizable views that float like zero gravity animation.

Floating Bubbles FloatingBubbles is a customizable views that float like zero gravity animation. $ pod try FloatingBubbles Features Create Multiple V

Chandan Sharda 18 Oct 11, 2022
Tinder/Bumble like user image with user details scroll animation

TinderUserProfile Tinder/Bumble like user image with user details scroll animation Add ProfileView.m,ProfileView.h class to your project. Set the clas

Souvick Ghosh 21 Jun 21, 2022
Genie - A Playground to recreate the macOS Genie Effect.

Genie A Playground to recreate the macOS Genie Effect. For more information, please read the accompanying blog post: Recreating the macOS Genie Effect

Harshil Shah 66 Nov 18, 2022
An easy way to add a simple, shimmering effect to any view in an iOS app.

Shimmer Shimmer is an easy way to add a shimmering effect to any view in your app. It's useful as an unobtrusive loading indicator. Shimmer was origin

Meta Archive 9.4k Dec 26, 2022
MotionBlur allows you to add motion blur effect to iOS animations.

MotionBlur MotionBlur allows you to add motion blur effect to your animations (currently only position's change). See the accompanying blog post to le

Arek Holko 1.5k Nov 3, 2022
RippleEffectView - A Neat Rippling View Effect

RippleEffectView Not only Uber-like animated screen background. RippleEffectView inspired by RayWenderlich.com article How To Create an Uber Splash Sc

Alex Sergeev 318 Dec 13, 2022
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.

LoadingShimmer An easy way to add a shimmering effect to any view with just single line of code. It is useful as an unobtrusive loading indicator. Thi

Jogendra 1.4k Jan 6, 2023
Instagram UI Redesign With SwiftUI

Instagram UI Redesign With SwiftUI Show some ❤️ and ⭐ the repo! Main Page YouTub

Vicente Nascimento 1 Feb 27, 2022
RetroBubbleText - A simple effect used in Retrogram which renders text with a fun bubble-style outline in SwiftUI

Retro Bubble Text This is a simple effect used in Retrogram which renders text w

Simeon Saëns 5 Aug 29, 2022
Shimmer: A super-light modifier that adds a shimmering effect to any SwiftUI View

SwiftUI-Shimmer ✨ Shimmer is a super-light modifier that adds a shimmering effec

Vikram Kriplaney 389 Jan 2, 2023
ChainPageCollectionView A custom View with two level chained collection views and fancy transition animation

ChainPageCollectionView A custom View with two level chained collection views and fancy transition animation. Demo Requirements iOS 9.0+ Xcode 8 Insta

Yansong Li 775 Dec 7, 2022
A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead. With DKChai

Draven 1.9k Dec 9, 2022
Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers. It's magic. Features Animate a

Robert-Hein Hooijmans 1.3k Nov 17, 2022