English Introduction

ThinkVerb

ThinkVerb is a set of APIS based on CoreAnimation. Instead of using CoreAnimation directly, ThinkVerb is programmed with a chain syntax and self-manages CAAnimation. You don’t need to manually create any CAAnimation and add it to the view yourself.

Thanks to this, ThinkVerb can quickly generate basic animations with very little code, not only that, but the code you write is fairly readable and easy to maintain.

Currently, ThinkVerb covers almost all basic animations, and you can easily combine multiple basic animations to create a complex animation. With native code, you might need a lot of code to do this, but with ThinkVerb, you can do the same amount of work in just a few lines of code.

Usage

ThinkVerb is simple. It has only one entry: ThinkVerb extends a UIView property: TVAnimation.

TVAnimation manages all the animation units. We call them sprites. All you have to do is create a Sprite, configure the Sprite, and activate the Sprite. So, the animation is activated, and the UIView will automatically start the animation.

For example, if you want to rotate your UIView forever, all you need is this:

NSString *rotation = view.TVAnimation.rotate.z.endAngle(M_PI * 2).repeat(-1).activate();
Copy the code

Or, if you want to define your own name for the Sprite you’re creating, you can write:

view.TVAnimation.rotate.z.endAngle(M_PI * 2).repeat(-1).activateAs(@"rotation");
Copy the code

This line of code is going to rotate your UIView around the z-axis from the current Angle of the UIView to M_PI * 2, assuming the current Angle is 0, so that’s a revolution. Repeat (-1) allows Sprite to repeat indefinitely. Finally, calling activate() activates the animation.

Normally, if you don’t let the Sprite repeat forever, or if you don’t let it linger at the end of the animation, the Sprite will automatically be removed and released, and you’ll need to manually remove the animation in the example above:

view.TVAnimation.clear();
Copy the code

The above line removes all animations from the view. Normally, this line is all you need to do. If you don’t want to affect other animations of the view, you can remove only the corresponding animations:

view.TVAnimation.existSprite(rotation).stop();
Copy the code

If you define your own name, you can do this:

view.TVAnimation.existSprite(@"rotation").stop();
Copy the code

This will stop the rotation and the Sprite will be removed and released. Otherwise, even if the View is released, the Sprite will not be released, causing a memory leak.

You can see more examples at ThinkVerbDemo.

ThinkVerb is also pretty easy to make complex animations, and you can even write a handgun:

view.TVAnimation.appearance.duration(3).timing(TVTiming.extremeEaseOut).end();
view.TVAnimation.contents.drawRange(nil,[UIImage imageNamed:@"1"]).didStop(^{
    view.TVAnimation.contents.drawRange([UIImage imageNamed:@"1"],[UIImage imageNamed:@"2"]).didStop(^{
        view.TVAnimation.contents.drawRange([UIImage imageNamed:@"2"],[UIImage imageNamed:@"3"]).didStop(^{
            view.TVAnimation.contents.drawRange([UIImage imageNamed:@"3"],[UIImage imageNamed:@"2"]).activate();
        }).activate();
    }).activate();
}).activate();
Copy the code

Installation

Using cocoapods

pod 'ThinkVerb'
Copy the code

Copy files

Copy all the source code in the sub-ThinkVERB folder into your project

Indexes

  • Basic

    • Move Moves a view from one point to another

    • Scale scales the view to some multiple

    • Rotate Rotates the view around the x/y/z axis

    • The shadow of the shadow offset/opacity radius, / / color to do animation.

    • Bounds animates the bounds of the view, noting that the animation depends on anchorPoint

    • The anchor point of the view is animated by anchor, which will not have any effect if it is animated alone, but only when it is combined with related animations

    • Translate moves animations with an offset, based on Transform3D, so you can apply it to Sublayer

    • It fades in and out

    • Contents animates the cotnents property, such as the Rect property, which animates the bitmap render return, within the range [0 0 1 1]

    • BackgroundColor Background transform

    • CornerRadius Rounded corner animation

    • Border animates the width and color of the view’s border

    • Path does keyframe animation of view, which generates curve animation through Bezier control points

  • Appearance

    Appearance Sprite can be used to configure default parameters for a view. If you want all sprites of a view to stay by default at the end of the animation, you can write before making the Sprite:

    view.TVAnimation.appearance.keepAlive(YES).end();
    Copy the code

License

ThinkVerb is released under the MIT license. See LICENSE for details.