UIView类的UIViewAnimationWithBlocks扩展 和 使用core an...

二.block方式:使用UIView类的UIViewAnimationWithBlocks扩展 ios

函数说明 编程

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void(^)(void))animations completion:(void(^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);//间隔,延迟,动画参数(好像没用?),界面更改块,结束块

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void(^)(void))animations completion:(void(^)(BOOL finished))completion 

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void(^)(void))animations 

+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void(^)(void))animations completion:(void(^)(BOOL finished))

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void(^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); //toView added to fromView.superview, fromView removed from its superview界面替换,这里的options参数有效

举例: 数据结构

[UIView animateWithDuration:0.7delay:0options:0animations:^(){
self.view.alpha = 0.2;
[self.view exchangeSubviewAtIndex:1withSubviewAtIndex:0];
self.view.alpha = 1;
} completion:^(BOOL finished)
{

}];

当areAnimationsEnabled为NO时,上面不能动画显示 app

[UIView transitionFromView:lImage toView:mImage duration:0.7options:options completion:^(BOOL finished)
{
if(finished) {
[self.view addSubview:lImage];
[self.view sendSubviewToBack:lImage];
[self.view sendSubviewToBack:mImage];

}];

options取值范围 ide

enum{
UIViewAnimationOptionLayoutSubviews = 1<< 0,
UIViewAnimationOptionAllowUserInteraction = 1<< 1, //turn on user interaction while animating
UIViewAnimationOptionBeginFromCurrentState = 1<< 2, //start all views from current value, not initial value
UIViewAnimationOptionRepeat = 1<< 3, //repeat animation indefinitely
UIViewAnimationOptionAutoreverse = 1<< 4, //if repeat, run animation back and forth
UIViewAnimationOptionOverrideInheritedDuration = 1<< 5, //ignore nested duration
UIViewAnimationOptionOverrideInheritedCurve = 1<< 6, //ignore nested curve
UIViewAnimationOptionAllowAnimatedContent = 1<< 7, //animate contents (applies to transitions only)
UIViewAnimationOptionShowHideTransitionViews = 1<< 8, //flip to/from hidden state instead of adding/removing

UIViewAnimationOptionCurveEaseInOut = 0<< 16, //default
UIViewAnimationOptionCurveEaseIn = 1<< 16,
UIViewAnimationOptionCurveEaseOut = 2<< 16,
UIViewAnimationOptionCurveLinear = 3<< 16,

UIViewAnimationOptionTransitionNone = 0<< 20, //default
UIViewAnimationOptionTransitionFlipFromLeft = 1<< 20,
UIViewAnimationOptionTransitionFlipFromRight = 2<< 20,
UIViewAnimationOptionTransitionCurlUp = 3<< 20,
UIViewAnimationOptionTransitionCurlDown = 4<< 20,
UIViewAnimationOptionTransitionCrossDissolve = 5<< 20,//ios5
UIViewAnimationOptionTransitionFlipFromTop = 6<< 20,//ios5
UIViewAnimationOptionTransitionFlipFromBottom = 7<< 20,//ios5
};
typedef NSUInteger UIViewAnimationOptions;

特色:快捷方便,效果更多.能够如上示例1那样实现界面个元素属性渐进变化的动态展现 函数

对于不太复杂的动画,上面的写法很精练,由于只有一条语句,若是动画太过复杂了,写在这样一条语句中就会显得冗长了,对于代码调试没那么方很是方便。
三:Core animation
coreanimation是以objc语言封装的一套图形渲染,投影以及动画的库的结合,使建立的用户界面变得很是容易,经过如下方法:
1:使用简单的编程方法实现高性能的合成
2:使用层对象建立复杂的用户界面。
3:轻量型数据结构,可以同时使几百个层产生动画。
4:不依赖于应用的主线程,动画在单独的线程里运行
5:改进了应用程序性能。应用程序只须要重画它变化的部分(局部刷新)。
6:灵活的布局管理方式
2.    相关类
使用core animation,开发者不须要使用底层的API或者OpenGL就能够建立漂亮的动画界面。
core animation类分红如下几个:
1:提供显示内容的层
2:动画和时间类
3:布局和约束类
4:将多个层分红几个原子更新的执行类
2.1 层(layer)
层是coreanimation的基础,视图的一个实例,有一个CALayer实例做为父层(superlayer)以及在这层上添加的全部子层,建立的层结构成为layertree
2.2动画和时间类
隐式动画
层的许多可视属性的改变能够产生隐式的动画效果,由于这些属性都默认与一个动画相关联。经过简单地设置可视的属性值,层会由当前值到被设置的值产生渐变的动画效果。好比,设置层的隐藏属性为真,将触发一个逐渐消失的动画效果。

显式动画
经过建立一个动画类和指定所须要的动画效果,显式的动画并不改变层的属性。
全部的核心动画类都由抽象类CAAnimation继承而来。CAAnimation采用CAMediaTiming协议。CAMediaTiming规定了动画的持续时间,速度以及重复次数。CAAnimation也采用了CAAction协议,该协议规定了在响应由层触发的动做时,开始一个动画的标准方式。

核心动画还提供其余的动画类
CATransition,
CATransition规定了影响整个层内容的转换效果,在动画期间,它使层产生渐变(fade),推拉(push)以及揭示(reveal)的动画效果。这些经常使用的转换效果能够经过核心绘图过滤器进行扩展。

CAAnimation,
CAAnimation容许大量的动画对象被分为几组,而且能够同时运行。
CAPropertyAnimation,是CAAnimation的子类,支持层在动画期间,为层指定一个关键路径。
CABasicAnimation.该类为层的属性提供了简单的插值。
CAKeyframeAnimation,
CAKeyframeAnimation提供关键帧动画的支持。你能够为层的属性指定一个关键路径 2.3布局管理类 CAKeyframeAnimation类用于管理全部子层的布局,每一个由CAConstraint类封装的实例描述了各个子层之间的几何位置关系。 2.4 执行管理类 可设置动画层的属性的修改必须是执行的一部分,CATransaction负责将许多动画分红几批原子型的更新进行显示。
相关文章
相关标签/搜索