[翻译] SCViewShaker

简介:

SCViewShaker

https://github.com/rFlex/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.

一个关于view的category,可以高度定制.只需要一行代码就可以让你的view振动起来.它支持几种振动的样式,可以让你设置振动间隔时间,振动速度以及振动的强度.

Usage

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

SCViewShaker以UIView的category的方式运行,提供了以下几个方法:

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

shake方法会让view振动几次后就停止,是一个便利的方法.

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:

shakeWithOptions:force:duration:iterationDuration:completionHandler:执行了一系列的可以设置的振动的动作,它有着如下的一些参数:

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

shakeOptions是一个枚举值选项,可以用或语句的方式组织参数.

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

force是一个振动幅度的参数.

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.

duration是所有振动动作的间隔时间,这个参数有可能因为shakeOptions参数的设置而失效.iterationDuration表示的是每一个振动能持续的时间.你也许需要设置一个很小的值(如0.02)才能达到一种好的振动效果.

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

completionHandler,如果设置为null,这是一个block,在振动结束后会被调用.

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. 

方向影响视觉上的振动效果.所有的参数都是基于强度1来计算的.

SCShakeOptionsDirectionRotate: The view will rotate from -90° to 90°. 这个view会从-90°到90°旋转

SCShakeOptionsDirectionHorizontal: The view will move horizontally from -frameWidth to +frameWidth. 这个view会从水平的-frameWidth值移动到+frameWidth值.

SCShakeOptionsDirectionVertical: The view will move vertically from -frameHeight to +frameHeight. 这个view会从垂直的-frameHeight值移动到+frameHeight值.

SCShakeOptionsDirectionHorizontalAndVertical: The view will randomly move horizontally or vertically. 这个view会随机的在水平或者垂直方向上移动.

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. 当振动结束后,这个振动将会逆序在执行一遍,设置这个参数会让振动时间变成双倍.

 

目录
相关文章
|
iOS开发 Android开发
|
iOS开发 编译器 Go
|
开发者 iOS开发
|
C# iOS开发 Perl