Code Monkey home page Code Monkey logo

scviewshaker's Introduction

SCViewShaker

About

A highly configurable UIView category for shaking a view. You start shaking your views with a one liner :). It supports a few different shaking styles (horizontal, vertical, rotate) and let you configure the duration, the speed and the shake strength.

Usage

SCViewShaker works as a category on UIView. It provides the following methods:

- (void)shake;

- (void)shakeWithOptions:(SCShakeOptions)shakeOptions force:(CGFloat)force duration:(CGFloat)duration iterationDuration:(CGFloat)iterationDuration completionHandler:(ShakeCompletionHandler)completionHandler
     
- (void)endShake
     
@property (readonly, nonatomic) BOOL isShaking

shake does a small shake on the view for a short amount of time. It was added as a convenience method.

shakeWithOptions:force:duration:iterationDuration:completionHandler: performs a new shake action with the complete control on how the shake will be done. It takes the follow parameters:

shakeOptions is an enum of options that can be activated by using the OR operator (like SCShakeOptionsDirectionRotate | SCShakeOptionsForceInterpolationNone).

force is the coefficient of force to apply on each shake iteration (typically between 0 and 1 even though nothing prevents you for setting a higher value if you want).

duration is the total duration of the shaking motion. This may be ignored depending of the options you set. iterationDuration is how long each shake iteration will last. You may want to set a very low value (like 0.02) if you want a proper shake effect.

completionHandler, if not null, is the block that will be invoked when the shake finishes.

Simple example

UIView *view = ...; // Grab a view from somewhere
[view beginShakingWithOptions:SCShakeOptionsDirectionRotate | SCShakeOptionsForceInterpolationExpDown | SCShakeOptionsAtEndRestart | SCShakeOptionsAutoreverse force:0.15 duration:1 iterationDuration:0.03 completionHandler:nil];

Options

Direction

The direction affects the visual effect of the shake effect. All value bounds shown here are based on a force of 1.

SCShakeOptionsDirectionRotate: The view will rotate from -90° to 90°.

SCShakeOptionsDirectionHorizontal: The view will move horizontally from -frameWidth to +frameWidth.

SCShakeOptionsDirectionVertical: The view will move vertically from -frameHeight to +frameHeight.

SCShakeOptionsDirectionHorizontalAndVertical: The view will randomly move horizontally or vertically.

Force interpolation

The force interpolation affects how the force changes in the time.

SCShakeOptionsForceInterpolationNone: The force will remain always the same as the one you provided.

SCShakeOptionsForceInterpolationLinearUp: The force will linearly changes from 0 to the one you provided.

SCShakeOptionsForceInterpolationLinearDown: The force will linearly changes from the one you provided to zero.

SCShakeOptionsForceInterpolationExpUp: The force will exponentialy changes from 0 to the one you provided.

SCShakeOptionsForceInterpolationExpDown: The force will exponentialy changes from the one you provided to zero.

SCShakeOptionsForceInterpolationRandom: The force will randomly change between 0 and the one you provided.

Action at end

The action at end defines what should happen when the shake completes

SCShakeOptionsAtEndRestart: The shake will be restarted automatically from the beginning.

SCShakeOptionsAtEndComplete: The shake will stop.

SCShakeOptionsAtEndContinue: The shake will contnue endlessly. The force won't change anymore when it reaches the duration.

Misc options

SCShakeOptionsAutoreverse: When the shake reaches the end, the shake will continue in the reverse order. Setting this value will double the effective duration.

Podfile

If you are using cocoapods, you can use this project with the following Podfile

pod "SCViewShaker", "~> 1.0"

scviewshaker's People

Contributors

rflex 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.