Giter Site home page Giter Site logo

mystique's Introduction

Mystique

Version License Platform

Introduction

Mystique wraps CoreAnimation with a nicer syntax to help you build up awesome animations.

Demo

demo

To implement above layer effect, all you need to write down:

// Animate the radiations
[radiation mt_startAnimations:^(MTAnimator *animate) {
    animate.opacity
        .from(@1.0)
        .to(@0.0)
        .animate(duration);
    animate.scale
        .from(@1.0)
        .to(@0.0)
        .animate(duration);
    animate.center
        .mt_from(fromPoint)
        .mt_to(toPoint)
        .animate(duration);
} completion:^{
    [radiation removeFromSuperlayer];
}];

// Animate the background circle
[circle mt_startAnimations:^(MTAnimator *animate) {
    animate.scale
        .byValues(@[@0.8, @(scale), @(scale)])
        .during(@[@0.0, @0.5, @1.0])
        .animate(duration);
    animate.opacity
        .from(@0.5)
        .to(@0.0)
        .animate(duration);
} completion:^{
    [circle removeFromSuperlayer];
}];

Check out the Mystique iOS Examples to get more details.

Installation

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

pod "Mystique"

Getting started

Basic usage

// Compose your animations in here.
[view mt_startAnimations:^(MTAnimator *animate) {
    
    // Animate origin x to 100 in 1s.
    animate.x.to(@100.0).animate(1.0);
    
    // Animate backgroundColor to red in 0.4s then change to yellow after 0.2s delay.
    animate.backgroundColor
        .to([UIColor redColor]).after(0.4)
        .delay(0.2).to([UIColor yellowColor]).animate(0.4);
}];

Attributes

Basic attributes

Attribute keyPath
bounds bounds
size bounds.size
origin position
center position
x position.x
y position.y
width bounds.size.width
height bounds.size.height
opacity opacity
backgroundColor backgroundColor
borderColor borderColor
borderWidth borderWidth
cornerRadius cornerRadius
scale transform.scale
scaleX transform.scale.x
scaleY transform.scale.y
anchor anchorPoint
rotateX transform.rotation.x
rotateY transform.rotation.y
rotateZ transform.rotation.z
rotate transform.rotation.z
path position

Advance attributes

Attribute keyPath Description
xOffset position.x Increase / decrease origin x by specific value
yOffset position.y Increase / decrease origin y by specific value
heightOffset bounds.size.width Increase / decrease width by specific value
widthOffset bounds.size.height Increase / decrease height by specific value
rotateOnPath position Animating along paths rotate to match the path tangent
reverseRotateOnPath position Animating along paths rotate to match the path tangent and auto reverse
fillColor fillColor CAShapeLayer only
strokeColor strokeColor CAShapeLayer only
strokeStart strokeStart CAShapeLayer only
strokeEnd strokeEnd CAShapeLayer only
lineWidth lineWidth CAShapeLayer only
miterLimit miterLimit CAShapeLayer only
lineDashPhase lineDashPhase CAShapeLayer only

Chaining Animations

An attribute should ended by animate(duration) function.

animate.width.to(@100).animate(1.0)

To chain an attribute with different values in different time can call after(duration) function.

animate.x.to(@50).after(1.0).to(@200).animate(2.0)

To delay an animation call the delay(duration) function.

// it will disappear in one second and appear again after two second delay
animate.opacity
    .to(@0.0).after(1.0)
    .delay(2.0).to(@1.0).animate(1.0)

Repeat and autoreverse

To repeat or autoreverse animations with the repeat(times), repeatInfinity() and autoreverse() functions.

Use it like CAKeyframeAnimation

Below is an example of how to set values and key times like CAKeyframeAnimation.

animate.scale
    .byValues(@[ @0.0, @1.1, @1.0 ])
    .during(@[ @0.0, @0.5, @1.0 ])
    .animate(duration);

/* the same as:
CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
keyframeAnimation.values = @[ @0.0, @1.1, @1.0 ];
keyframeAnimation.keyTimes = @[ @0.0, @0.5, @1.0 ];
keyframeAnimation.duration = duration;
*/

Debug

Set logEnable to YES will print all animations details for you to debug.

animate.logEnable = YES

Credit

Thanks their incredible works!

JHChainableAnimations

Masonry

License

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

mystique's People

Contributors

gbammc avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  avatar

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.