GithubHelp home page GithubHelp logo

augustrush / stellar Goto Github PK

View Code? Open in Web Editor NEW
2.9K 68.0 227.0 13.78 MB

A fantastic Physical animation library for swift

License: MIT License

Swift 99.65% Ruby 0.21% Objective-C 0.14%
curve animation physical uidynamics swift-3 ios

stellar's Introduction

Carthage compatible Packagist codebeat badge Travis branch Cocoapods badge

A fantastic Physical animation library for swift(Not Just Spring !!!), it is base on UIDynamic and extension to it, friendly APIs make you use it or custom your own animation very easily!

Support

Integration

Cocoapods(iOS 8+)

  • You can use Cocoapods to install Stellar by adding it to your Podfile:
platform :ios, '8.0'
use_frameworks!

target 'YourApp' do
    pod 'Stellar', :git => 'https://github.com/AugustRush/Stellar.git'
end

Carthage (iOS 8+)

  • You can use Carthage to install Stellar by adding it to your Cartfile:
github "AugustRush/Stellar"

Manually (iOS 8+)

To use this library in your project manually you may:

  • for Projects, just drag Stellar Sources to the project tree
  • for Workspaces, include the whole StellarDemo.xcodeproj

Features

- View's Animation
- Layer's Animation
- Chainable (every step can be observed)
- File configurable (come soon)

Animations

- Basic
- Gravity
- Snap
- Attachment
- Push
- Collsion(come soon)

Animatable type

- Float
- CGFloat
- Double
- CGSize
- CGPoint
- CGRect
- UIColor
- ......(Any Intrpolatable)

Easing Curve (Base Animation)

- Default
- EaseIn
- EaseOut
- EaseInEaseOut
- Linear
- SwiftOut
- BackEaseIn
- BackEaseOut
- BackEaseInOut
- BounceOut
- Sine
- Circ
- ExponentialIn
- ExponentialOut
- ElasticIn
- ElasticOut
- BounceReverse
- Custom(Double, Double, Double, Double)

On display

Funny demo's gif(s)

Chainable

  1. Common

for (index,line) in leftLines.enumerate() {
    let delay = Double(index) * 0.2
    
    line.moveX(200).duration(2).easing(.SwiftOut).delay(delay)
        .then().moveX(-200).rotateY(1.43).easing(.SwiftOut)
        .makeColor(UIColor.greenColor()).repeatCount(100)
        .autoreverses().duration(2).animate()
 }
        
 for (index,line) in rightLines.enumerate() {
    let delay = Double(index) * 0.2
    
    line.moveX(-200).duration(2).easing(.SwiftOut).delay(delay)
        .then().moveX(200).rotateY(1.43).easing(.SwiftOut)
        .makeColor(UIColor.purpleColor()).repeatCount(100)
        .autoreverses().duration(2).animate()
 }
  1. every step completion observable

animateView.makeSize(CGSizeMake(50, 150)).snap(0.3).completion({
                print("First step")
            })
            .then().moveX(-100).moveY(-50).anchorPoint(CGPointMake(1, 1)).duration(1).completion({
                print("Second step!")
            })
            .then().rotate(CGFloat(M_PI)).attachment(0.3, frequency: 0.8).completion({
                print("Third step!")
            })
            .then().moveY(500).completion({
                print("last step, all completion")
            })
            .animate()

Snap Curve

Attachment Curve

Gravity Curve

Push Curve

Basic Curve

To do

- File configurable
- Easily Interactive Animations
- Collision
- Mutilple View/Layer performance
- More demos

Licence

Copyright (c) 2016 

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

stellar's People

Contributors

augustrush avatar korstudio avatar mikker 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stellar's Issues

Buggy examples

just run any example from demo and click multiple times - animation breaks

Swift 3 errors

I love Stellar. Animations with Swift like they should be. Thanks.
but...
Swift 3 branch seems to throw compile errors. Any plans on fixing this? Swift 3 officially out today.
thanks.

Pod

Would be amazing if this could be installed using CocoaPods :)

When I use OC, import the swift code, found that there is no easing and other methods


@interface CALayer (SWIFT_EXTENSION(Stellar))
@EnD

@interface UIColor (SWIFT_EXTENSION(Stellar))

  • (void)fallTo:(UIColor * _Nonnull)to magnitude:(double)magnitude render:(void (^ _Nonnull)(UIColor * _Nonnull))render completion:(void (^ _Nullable)(void))completion;
  • (void)snapTo:(UIColor * _Nonnull)to damping:(CGFloat)damping render:(void (^ _Nonnull)(UIColor * _Nonnull))render completion:(void (^ _Nullable)(void))completion;
  • (void)attachmentTo:(UIColor * _Nonnull)to damping:(CGFloat)damping frequency:(CGFloat)frequency render:(void (^ _Nonnull)(UIColor * _Nonnull))render completion:(void (^ _Nullable)(void))completion;
  • (void)pushedTo:(UIColor * _Nonnull)to render:(void (^ _Nonnull)(UIColor * _Nonnull))render completion:(void (^ _Nullable)(void))completion;
    @EnD

@interface UIDynamicBehavior (SWIFT_EXTENSION(Stellar))
@EnD

@Class UIView;

@interface UILabel (SWIFT_EXTENSION(Stellar))

  • (UIView * _Nonnull)makeTextColor:(UIColor * _Nonnull)color;
    @EnD

@interface UITextView (SWIFT_EXTENSION(Stellar))

  • (UIView * _Nonnull)makeTextColor:(UIColor * _Nonnull)color;
    @EnD

@interface UIView (SWIFT_EXTENSION(Stellar))

  • (BOOL)configureWithJSON:(NSString * _Nonnull)str error:(NSError * _Nullable * _Null_unspecified)error;
    @EnD

@interface UIView (SWIFT_EXTENSION(Stellar))

  • (UIView * _Nonnull)moveX:(CGFloat)increment;
  • (UIView * _Nonnull)moveY:(CGFloat)increment;
  • (UIView * _Nonnull)moveTo:(CGPoint)point;
  • (UIView * _Nonnull)makeColor:(UIColor * _Nonnull)color;
  • (UIView * _Nonnull)makeAlpha:(CGFloat)alpha;
  • (UIView * _Nonnull)rotate:(CGFloat)z;
  • (UIView * _Nonnull)rotateX:(CGFloat)x;
  • (UIView * _Nonnull)rotateY:(CGFloat)y;
  • (UIView * _Nonnull)rotateXY:(CGFloat)xy;
  • (UIView * _Nonnull)makeWidth:(CGFloat)width;
  • (UIView * _Nonnull)makeHeight:(CGFloat)height;
  • (UIView * _Nonnull)makeSize:(CGSize)size;
  • (UIView * _Nonnull)makeFrame:(CGRect)frame;
  • (UIView * _Nonnull)makeBounds:(CGRect)bounds;
  • (UIView * _Nonnull)scaleX:(CGFloat)x;
  • (UIView * _Nonnull)scaleY:(CGFloat)y;
  • (UIView * _Nonnull)scaleXY:(CGFloat)x :(CGFloat)y;
  • (UIView * _Nonnull)cornerRadius:(CGFloat)radius;
  • (UIView * _Nonnull)borderWidth:(CGFloat)width;
  • (UIView * _Nonnull)shadowRadius:(CGFloat)radius;
  • (UIView * _Nonnull)zPosition:(CGFloat)position;
  • (UIView * _Nonnull)anchorPoint:(CGPoint)point;
  • (UIView * _Nonnull)anchorPointZ:(CGFloat)z;
  • (UIView * _Nonnull)shadowOffset:(CGSize)offset;
  • (UIView * _Nonnull)shadowColor:(UIColor * _Nonnull)color;
  • (UIView * _Nonnull)shadowOpacity:(float)opacity;
  • (UIView * _Nonnull)makeTintColor:(UIColor * _Nonnull)color;
  • (UIView * _Nonnull)completion:(void (^ _Nonnull)(void))c;
  • (UIView * _Nonnull)then;
  • (UIView * _Nonnull)then;
  • (void)animate;
  • (void)cancelAllRemaining;
    @EnD

How to "glue" animation

I want to design an animation by chaining several animations in a programmatically way.

I tried the following without success:

aView = aView.moveX(5.0).duration(2.0).completion({ do_something() }).then()
...
aView = aView.moveX(7.0).duration(1.0).completion({ do_something() }).then()

aView.animate()

How to achieve this?

Affine Transform

What are your thought about this?

Oftentimes I need to also animate affine scale. However this one is not supported by stellar. I wrote the following set of extensions to make it uniform with Stellar's syntax.

What are your thoughts? Do you see any systemic issue?

`struct CABasicAnimatedView {

let view: UIView
let animation: CABasicAnimation

}

extension UIView {

func makeAffineUniformScale(from from: CGFloat, to: CGFloat) -> CABasicAnimatedView {
    
    let animation = CABasicAnimation(keyPath: KeyPaths.Transform.scale)
    let animatedView = CABasicAnimatedView(view: self, animation: animation)
    
    animatedView.animation.fromValue = from
    animatedView.animation.toValue = to
    
    return animatedView
}

}

extension CABasicAnimatedView {

func duration(duration: NSTimeInterval) -> CABasicAnimatedView {
    
    self.animation.duration = duration
    
    return self
}

func timingFunction(timingFunction: CAMediaTimingFunction) -> CABasicAnimatedView {
    
    self.animation.timingFunction = timingFunction
    
    return self
}

func animate() {
    
    CATransaction.begin()
    self.view.layer.addAnimation(self.animation, forKey: nil)
    CATransaction.commit()
    
    self.view.transform = CGAffineTransformMakeUniformScale(self.animation.toValue as! CGFloat) }

}

func CGAffineTransformMakeUniformScale(scale: CGFloat) -> CGAffineTransform {

return CGAffineTransformMakeScale(scale, scale)

}`

cancel/remove all animations

Still awesome animation library. Loving it the more I use it.

Feature request. Would be nice if I could call cancelAllAnimations() on a UIView. and it'll stop all ongoing and planned animations.

makeAlpha seems not working

Hi,

Seems that makeAlpha is not working, or maybe I'm doing something wrong.
Can you add an example of how to use it on the demo view controllers?

Thanks

Future

Hi,

I am using the library with solid success. However I am a bit stressed by the stale development lately. What are your plans honestly?

太赞了

不知不觉又新推出一开源项目

Does it work with autolayout ?

Hi, I have just got an issue when I try to animate the appearance of a view by extending its width from 0 to full width, from left to right.

view.makeFrame(CGRect(origin: origin, size: CGSize(width: 0, height: view.bounds.height))).makeAlpha(1).duration(0).then()
            .makeFrame(CGRect(origin: origin, size: CGSize(width: width, height: view.bounds.height))).duration(1).animate()

The view is expected to extend from the origin of the view.

            |                                                   |               
            |----->-------------->-----------------------------
            |                                                   |  
            |                                                   |  
            |                                                   | 

(view left border) (view right border)

However, it did extend from the center of the view.

            |                                                   |               
            |                           ---->------------->---------------------------
            |                                                   |  
            |                                                   |  
            |                                                   |  

In the storyboard, autolayout of this view is set as having 0 padding to the left border of the container.

"Unsupport this animation type!" exception

With 0.66 this exception is thrown on very basic animation:

myView.makeAlpha(0.0)
      .duration(aDuration)
      .autoreverses()
      .repeatCount(someRepetitions)
      .completion {
            // Some statements
              myView.removeFromSuperview()
            }
      .animate()

Let's say it's a find of flash.

I tried other animation like makeSizeor makeColor but same behavior.

This flash portion of code is called several times on a sequence basis. On the first call everything is fine. The exception is raises on the second call.
Between these two calls of flash there is an animation using CATransaction. On the completion block of this animation the second call of flash is then made.

CATransaction.begin()
CATransaction.setCompletionBlock({
      // call to flash animations
})

...

CATransaction.commit()

This error came after I decided to use CATransaction to use it's completion block.

Unable into install via CocoaPods

I've noticed there's a podspec file available but some for strange reason I can't find the repo on CocoaPods.

pod 'Stellar'

Returns a Unable to find a specification for Stellar error.

Although downloading straight from the source works.

pod 'Stellar', :git=>'https://github.com/AugustRush/Stellar.git'

Update library in Cocoapods

Hi,

Interesting library!

Latest release here is 0.66, while on pods you can only find 0.61. Any reason to keep it that way? Could you update it there too? So we don't need to point this specific branch.

Thank you,
H.

Stellar does not play well with Carthage

For months now I have problem using Stellar with Carthage. I have to ways to solve the problems: 1/ by "manually" building Stellar framework after changing stuff in Xcode project or 2/ by adding sources to my project. But as for now the last option does not work because the code imported using Carthage is not the last one on GitHub...

So there is definitely something wrong with Carthage.

Spanish translate

Hello, I would like to collaborate with the Spanish translation, is it done?

"has no member" error

I want to use Stellar with my project but I have this Value of type 'UIView' has no member error in my very first attempt to use Stellar on an UIView.

I use Carthage to install Stellar the same way as other libraries. It's like Stellar is not "installed". Installation using Stellar 0.65 is OK, and the usual Carthage installation has been followed.
Then, I used the direct inclusion of Sourcesdirectory and everything is fine.

I have clean project. This is a weird behavior... Any idea? Is there special configuration for Carthage command?

Using makeAlpha on 0.66 generates crash

Using makeAlpha of 0.66 generates the Unsupport this animation type!
(btw, Unsupport is not word ... Do not support this animation type! is better)

Reverting back to 0.65 fixed the issue by using the following in the Podfile
pod 'Stellar', :git => 'https://github.com/AugustRush/Stellar', :commit => '5249167900b1eb136ce71543af7817a9fa5535cb'

scaleXY doesn't work as expected

Unless the library works differently it is ususally expected that a scale of 1 always return the identity matrix scalling column back.

However here with Stellar (and thanks for you great work btw), this not the case.
A simple exemple with

myView.scaleXY(0.9,0.9).animate()
// later on: 
myView.scaleXY(1.0,1.0).animate()

shows that the scaling factor of 1.0 leave the scale of the view unchanged.
And changing the second call to myView.scaleXY(1.1,1.1).animate() doesn't return the view to its original scale either (that, I have trouble understanding).

If you have any question regarding this, let me know :)

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.