Giter Site home page Giter Site logo

shoheiyokoyama / gemini Goto Github PK

View Code? Open in Web Editor NEW
3.2K 56.0 188.0 3.62 MB

Gemini is rich scroll based animation framework for iOS, written in Swift.

Home Page: https://www.youtube.com/watch?v=bPtq5E6lKzw&utm_content=bufferfa3fd&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer

License: MIT License

Swift 96.52% Ruby 3.30% Makefile 0.17%
swift swift-library ios ios-animation animation-effects animation-library uicollectionview animation-3d cocoapods carthage

gemini's Introduction

Overview

What is the Gemini?

Gemini is rich scroll based animation framework for iOS, written in Swift. You can easily use GeminiCollectionView, which is a subclass of UICollectionView.

It enables you to make multiple animation which has various and customizable properties, and moreover can create your own custom scroll animation.

Gemini also provides a fluent interface based on method chaining. you can use this intuitively and simply.

collectionView.gemini
    .circleRotationAnimation()
    .radius(400)
    .rotateDirection(.clockwise)

Features

Platform Cocoapods Carthage compatible License Swift pod

  • Rich animation with scrolling
  • Easily usable
  • Highly customizable
  • Several types of animations and properties
  • Supports vertical and horizontal flow layout
  • Supports easing function
  • Supports Swift5.0
  • Fluent interfaces based on method chaining
  • Compatible with Carthage
  • Compatible with CocoaPods
  • Example project with lots of stock animations
  • And More...

Contents

The following animation types are available. See sample code here for details.

In addition, you can also customize the following properties for the above animation types.

It's a cube animation like Instagram. If you would like to customize the cube animation, change cubeDegree. If cubeDegree is 90, it moves like a regular hexahedron.

collectionView.gemini
    .cubeAnimation()
    .cubeDegree(90)

An animation moves in a circle. You can change circleRadius and CircleRotationDirection.

collectionView.gemini
    .circleRotationAnimation()
    .radius(450) // The radius of the circle
    .rotateDirection(.clockwise) // Direction of rotation. 
    .itemRotationEnabled(true) // Whether the item rotates or not.

Available for Roll, Pitch and Yaw animation. These rotation animation are designed based on 3-Dimensional vector. Figure-1 shows direction of rotation based on device.

Figure-1 Pitch, roll, and yaw axes

Each types of rotation animation has RotationEffect(e.g. RollRotationEffect) and degree of rotation.

Customize RotationEffect (up, down, sineWave, reverseSineWave) and degree of rotation.

In the case of rollRotation, like this:

collectionView.gemini
    .rollRotationAnimation()
    .degree(45)
    .rollEffect(.rollUp)

The scaleUp gradually increases frame size, scaleDown decreases.

collectionView.gemini
    .scaleAnimation()
    .scale(0.75)
    .scaleEffect(.scaleUp) // or .scaleDown

You can flexibly and easily customize scroll animation. Customize properties of GeminiAnimation.custom such as scale, scaleEffect, rotationAngle, translation, easing, shadowEffect, alpha, cornerRadius, backgroundColor, anchorPoint, etc.

The animation of gif is customized in the following way:

collectionView.gemini
    .customAnimation()
    .translation(y: 50)
    .rotationAngle(y: 13)
    .ease(.easeOutExpo)
    .shadowEffect(.fadeIn)
    .maxShadowAlpha(0.3)

Or right side of gifs is customized as follows:

collectionView.gemini
    .customAnimation()
    .backgroundColor(startColor: lightGreenColor, endColor: lightBlueColor)
    .ease(.easeOutSine)
    .cornerRadius(75)

There are more sample code at CustomAnimationViewController.swift.

Gemini supports various easing functions based on distance of scroll.

  • linear
  • easeInQuad
  • easeOutQuad
  • easeInOutQuad
  • easeInCubic
  • easeOutCubic
  • easeInOutCubic
  • easeInQuart
  • easeOutQuart
  • easeInOutQuart
  • easeInQuint
  • easeOutQuint
  • easeInOutQuint
  • easeInSine
  • easeOutSine
  • easeInOutSine
  • easeInExpo
  • easeOutExpo
  • easeInOutExpo
  • easeInCirc
  • easeOutCirc
  • easeInOutCirc

Default value is ShadowEffect.none. Return shadowView in your custom class, which is a subclass of GeminiCell.

  • fadeIn
  • nextFadeIn
  • previousFadeIn
  • fadeOut
  • none
class CustomCollectionViewCell: GeminiCell {
    @IBOutlet weak var customShadowView: UIView!
    override var shadowView: UIView? {
        return customShadowView
    }
}
  1. Use Gemini classes

Gemini is designed to be easy to use. Use GeminiCollectionView and GeminiCell. These classes is subclass of UICollectionView, UICollectionViewCell.

  1. Configure animation

Configure animation with fluent interface based on method chaining. You can develop expressive code that enhances readability.

  1. Call function for animation

Finally, call animateVisibleCells() in scrollViewDidScroll(_:)

NOTE: If you want to adapt animation immediately after view is displayed, call animateCell(_:) in collectionView(_:cellForItemAt:) and collectionView(_:willDisplay:forItemAt:).

// Import Gemini
import Gemini

// Inherite GeminiCell
class CustomCell: GeminiCell {
    ...
}

// Conform to UICollectionViewDelegate and UICollectionViewDataSource
class CustomViewController: UIViewController: UICollectionViewDelegate, UICollectionViewDataSource {

    // Inherite GeminiCollectionView
    @IBOutlet weak var collectionView: GeminiCollectionView!

    ...

    // Configure animation and properties
    func configureAnimation() {
        collectionView.gemini
            .circleRotationAnimation()
            .radius(400)
            .rotateDirection(.clockwise)
    }

    // Call animation function
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        collectionView.animateVisibleCells()
    }

    func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        if let cell = cell as? GeminiCell {
            self.collectionView.animateCell(cell)
        }
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell
        self.collectionView.animateCell(cell)
        return cell
    }

See Example, for more details.

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

  • Xcode 10.2.1
  • Swift 5.0

CocoaPods

Gemini is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Gemini"

Carthage

Add the following line to your Cartfile:

github "shoheiyokoyama/Gemini"

Shohei Yokoyama

License

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

gemini's People

Contributors

ezra-black avatar kornerr avatar rinov avatar shoheiyokoyama avatar ziishaned avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gemini's Issues

swift 4 Compiler Error

Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
screen shot 2017-10-19 at 01 31 24

Zoomed image lagging at time of swipe

I have used Gemini cube effect in my scrollview image cell. After zooming image when I try to swipe image it is lagging. it is working fine in UICollectionViewCell

CompositionalLayout - Feature Request

Hi,

Gemini seems to be not working when using a UICollectionViewDiffableDataSource along with a UICollectionViewCompositionalLayout.

The scrolling function
func scrollViewDidScroll(_ scrollView: UIScrollView)
is not called on scroll in these layouts by design, rather:

section.orthogonalScrollingBehavior = .groupPagingCentered
section.visibleItemsInvalidationHandler = { visibleItems, scrollOffset, layoutEnvironment in
                 self.collectionView.animateVisibleCells()  
}

is used to detect scrolling for each section, but calling the animation function seems to only do the animation once initially.

I'm also calling the animation in

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {

        guard let customCell = cell as? MyCollectionCell else { return }
        self.collectionView.animateCell(customCell)
}

and its set as

collectionView.gemini.customAnimation().translation(x: 0, y: 50, z: 0).rotationAngle(x: 0, y: 13, z: 0).ease(.easeOutExpo)

Application crash

If we create a collection view in a collectionviewCell(GeminiCell), application crash on flow layout. Can you tell me the solution.

Accessibility Support

There are many small improvements that would make Gemini accessible to all users.
I can't take this on right now but would love to be of assistance to anyone who can!

Currently I am using iCarousel using unmerged PR, which would be a great example to look at.

Device Rotate Support

Hi, great job making this library public. i love it.

I only have faced one problem.

when using this with device rotation enabled. its not resizing correctly.

How can this be fixed?

check this for more info: (used in the example with enabled rotate left,right)
https://streamable.com/phl39

Infinite scrolling support

It is possible to loop the rotation in order that at the end of the last cell it loops back to the first?

For Xcode9.3 and iOS 11.3, Expression was too complex

At line 191 in GeminiAnimationModel.swift, The Method for backgorundColor has Swift Compiler Error.
The Error Message is as follows.
Message: Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

CollectionView didSelectItemAt not being called

Hello,

I've created a pull request here which shows a problem where didSelectItemAt in UICollectionViewDelegate is not being called when I use Gemini.

Here is the link:

#2

Does anyone else have this problem or knows how to work around this?

Thank you.

Unknown class _TtC720GeminiCollectionView in Interface Builder file.

Hi.
Thanks for this awesome framework.
I implemented Gemini using Carthage.
I get this error at run time:
Unknown class _TtC720GeminiCollectionView in Interface Builder file.

On first line of this code:

        collectionView.gemini
            .circleRotationAnimation()
            .radius(400)
            .rotateDirection(.clockwise)
    }

Scroll to specific item programmatically using current animation

I'm using to following code to set the flow layout in example project's scale up horizontal animation. The result of this setting is only shows about 40px width of previous item, and the next item is invisible while paging animation is done.

// Setting of UICollectionViewFlowLayout let layout = UICollectionViewPagingFlowLayout() layout.scrollDirection = scrollDirection layout.itemSize = CGSize(width: view.bounds.width - 120, height: view.bounds.height - 400) layout.sectionInset = UIEdgeInsets(top: 200, left: 80, bottom: 200, right: 40) layout.minimumLineSpacing = 10 layout.minimumInteritemSpacing = 10 collectionView.collectionViewLayout = layout collectionView.decelerationRate = UIScrollViewDecelerationRateFast

However, if I trying to implement an action which scroll to the previous item when user click on the previous item. I'm using the following codes. The result comes out is the previous cell moved to center, and the next/last cell are displayed on right/left with 20px width respectively.

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true) }

How to do the programatic scrolling which can be same of the animation that performed by paging scrolling?

CircleRotation custom radius and item size

Hi,

Thanks for this great library, I am facing one issue

How to calculate radius, number of visible cells, for CircleRotation ?

I am trying to create a wheel kind of layout like demo in this link Wheel Demo

Can you please guide me. Thanks

SwiftUI Support

This library looks awesome! Is there any plans for SwiftUI support? Or any examples of integrating this with a SwiftUI-based project?

could not install pod in Xcode 9.3

pod init

――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Command

/usr/local/bin/pod init

Report

  • What did you do?

  • What did you expect to happen?

  • What happened instead?

Stack

   CocoaPods : 1.3.1
        Ruby : ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
    RubyGems : 2.5.2
        Host : Mac OS X 10.13.4 (17E202)
       Xcode : 9.3 (9E145)
         Git : git version 2.15.1 (Apple Git-101)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 08efba4093074e5433f487070b5fbcbfb9fb5f6f

Plugins

cocoapods-deintegrate : 1.0.1
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.0.0
cocoapods-trunk       : 1.3.0
cocoapods-try         : 1.1.0

Error

RuntimeError - [Xcodeproj] Unknown object version.
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.4/lib/xcodeproj/project.rb:217:in `initialize_from_file'
/Library/Ruby/Gems/2.3.0/gems/xcodeproj-1.5.4/lib/xcodeproj/project.rb:102:in `open'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command/init.rb:41:in `validate!'
/Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:333:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/lib/cocoapods/command.rb:52:in `run'
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.3.1/bin/pod:55:in `<top (required)>'
/usr/local/bin/pod:22:in `load'
/usr/local/bin/pod:22:in `<main>'

――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

[!] Oh no, an error occurred.

Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=%5BXcodeproj%5D+Unknown+object+version.&type=Issues

If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new

Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

Don't forget to anonymize any private data!

Looking for related issues on cocoapods/cocoapods...

and 37 more at:
https://github.com/cocoapods/cocoapods/search?q=[Xcodeproj]%20Unknown%20object%20version.&type=Issues&utf8=✓

SPM Support

Could you please add swift package manager support ASAP?

Value of type '[UICollectionViewCell]' has no member 'compactMap'

The newest version get error in the method below.

visibleCellsValue of type '[UICollectionViewCell]' has no member 'compactMap'

// Call this method in `scrollViewDidScroll(_:)`.
    public func animateVisibleCells() {
        guard let model = animationModel, model.isEnabled else { return }

        visibleCells
            .compactMap { $0 as? GeminiCell }
            .forEach { [weak self] cell in
                self?.animateCell(cell)
            }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.