一 Core Animation
核心动画是分三层进行的-动画层树(CALayer Tree)M、展示树(Presentation Tree)、以及渲染树(Render Tree)。
每一个动画层有着自己的坐标系,这个坐标系独立于其父动画层。在iOS上,动画层的坐标系原点在左上角,坐标轴向右向下延伸。
动画有隐式和显示之分。隐式动画指的是,无须创建动画对象,只需改变动画层的属性,让核心动画自己去完成动画效果。显示动画指的是,需要自己创建和管理动画对象,并且将它们应用到动画层,才能显示动画效果。
UIImageView有animationImages属性,如果将一个UIImage对象构成的NSArray数组赋值给它,UIImageView将轮流显示这些图像。给UIImageView发送startAnimating消息,那么它就开始逐帧显示动画了。animationDuration属性标明了每一帧动画占用的时间,默认1/30秒。animationRepeatCount属性标明了动画重复次数,缺省为0,表示不断重复下去。
方法:
+beginAnimations:context:标志动画代码开始
+commitAnimations:标志动画代码结束,程序会创建新的线程,并准备运行动画
+setAnimationStartDate:设置动画开始时间。
+setAnimationsEnabled:可以用来开启或禁止动画显示。
+setAnimationDelegate:设置代理,可以接收到UIView的代理方法。
+setAnimationWillStartSelector:设置动画开始前将发送给代理的方法。
+setAnimationDidStopSelector:设置动画停止后将发送给代理的方法。
+setAnimationDuration:设置动画持续时间。
+setAnimationDelay:设置一段时间,动画将在这段时间后开始执行。不建议使用
+setAnimationCurve:设置动画曲线,如开始慢,后面快。
+setAnimationRepeatCount:设置动画重复次数。
+areAnimationEnabled:检查是否已经启动动画。
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
CGAffineTransform newTransform = CGAffineTransformRotate(view.transform, 3.14/2);
view.trnsform = newTransform;
[UIView commitAnimations];
//简单移动
imageView.transform = CGAffineTransformIdentity;
imageView.frame=CGRectMake(0, 100, 320, 320);
[UIView beginAnimations:@"clearmemory"context:imageView];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton)];
imageView.frame=CGRectMake(34, 0, 320, 320);
[UIView commitAnimations];
//动画曲线
[UIView beginAnimations:nilcontext:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
// UIViewAnimationCurveEaseInOut, // slow at beginning and end
//UIViewAnimationCurveEaseIn, // slow at beginning
//UIViewAnimationCurveEaseOut, // slow at end
//UIViewAnimationCurveLinear //恒定速度
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
imageView.frame=CGRectMake(22, 0, 320, 320);
[UIView commitAnimations];
//反向重复
[UIView beginAnimations:@"animation3" context:imageView1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:10];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
imageView1.alpha=0;
[UIView commitAnimations];
// 延时,缓入,缓出
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
imageView.frame=CGRectMake(120, 0, 200, 200);
[UIView commitAnimations];
//缓出
[UIView beginAnimations:nilcontext:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
imageView.frame =CGRectMake(235, 144, 200 , 200);
[UIView commitAnimations];
//放大
[UIView beginAnimations:nilcontext:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
imageView.transform=CGAffineTransformMakeScale(2, 2);
[UIView commitAnimations];
//旋转放大这里用到179.9是因为你不管前面加-+都是逆时针
[UIView beginAnimations:nilcontext:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
CGAffineTransform tranform1=CGAffineTransformMakeScale(1, 1);
CGAffineTransform tranform3=CGAffineTransformMakeTranslation(200, 200);
CGAffineTransform tranform2=CGAffineTransformMakeRotation(179.9*M_PI/180.0);
imageView.transform =CGAffineTransformConcat(tranform1, tranform3);
[UIView commitAnimations];
//平移旋转
[UIView beginAnimations:nilcontext:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
CGAffineTransform tranform1=CGAffineTransformMakeTranslation(-200, 0);
// CGAffineTransform tranform2= CGAffineTransformMakeRotation(179.9*M_PI/180.0);
imageView.transform =CGAffineTransformRotate(tranform1, 359.9*M_PI/180.0);
[UIView commitAnimations];
//翻转
[UIView beginAnimations:nilcontext:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRightforView:self.viewcache:YES];
//UIViewAnimationTransitionFlipFromLeft 从左往右翻
//UIViewAnimationTransitionFlipFromRight从右往左翻
//UIViewAnimationTransitionCurlUp 从上往下翻
//UIViewAnimationTransitionCurlDown 从下往上翻
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(enablebutton:)];
imageView.hidden=YES;
imageView1.hidden=NO;
[UIView commitAnimations];
//淡入淡出
CATransition *animation = [CATransition animation];
animation.duration = 0.75f; //动画时长
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
animation.delegate = self;
animation.type = kCATransitionFade; //过度效果
//kCATransitionFade 淡入淡出
//kCATransitionMoveIn 移入移出
//kCATransitionPush 压入推出
//kCATransitionReveal 覆盖移除
animation.subtype=kCATransitionFromLeft;
//kCATransitionFromRight 从左
//kCATransitionFromLeft 从右
//kCATransitionFromTop 从上
//kCATransitionFromBottom 从下
[self.view.layer addAnimation:animation forKey:@"animation"];
imageView.hidden=YES;
imageView1.hidden=NO;
-(void)enablebutton:(id)sender
{
imageView.transform=CGAffineTransformIdentity;
imageView.frame=CGRectMake(0, 0, 200, 200);
//btn.enabled=NO;
}
相关推荐
UIView 震动动画效果 AFViewShaker ,AFViewShaker 是一个简单的工具用来执行 。 使用方法: AFViewShaker *...
它还为CABasicAnimation和动画选项的访问器提供了简单的构造器。例子您的UIView子类具有自定义动画属性: @implementation ANPCornerView@dynamic cornerRadius;- ( CGFloat ) cornerRadius { return self.
iOS 中对UIView简单的封装,换个说法:运用帧动画封装了一个HUD,使用起来简单方便,只需要调用 [RKJAnimatingHUD RKJStarAnimatingForView:self];或者 [RKJAnimatingHUD RKJStopAnimatingForView:self];一个类方法...
DaisyChain - 一个微框架让UIView动画链接?变得超级简单
该类继承UIView,展示一个不断滚动的波浪动画,可以通过改变属性来控制波浪的颜色、大小、振幅、速度、边框等属性,且可以直接判断是否为正圆显示,使用就像普通UIView一样简单。
RNPulseButton:简单和可定制的iOS脉冲动画效果按钮
对系统动画做了简单封装,UIView扩充类别,一句话可调用系统各种动画。可设置动画类型,时间,初始方向。
iOS 中对UIView简单的封装,换个说法:运用帧动画封装了一个HUD,使用起来简单方便,只需要调用 [RKJAnimatingHUD RKJStarAnimatingForView:self];或者 [RKJAnimatingHUD RKJStopAnimatingForView:self];一个类方法...
使用Swift语言实现一个简单的帧动画
用animation实现UIView动画效果,简单上中下移动
UIView+VMAnimations概述UIView (VMAnimations) 扩展了 UIView 类以提供一种简单的方法来为 UIView 对象设置动画。用法这些方法可能是不言自明的: @interface UIView (VMAnimations)#pragma mark - Pulse Animation...
在你调用 beginAnimations:context:方法来启动一个动画后,动画并不会立即被执行,直 到你调用 UIView 类的 commitAnimations 类方法。你对一个视图对象执行的介于 beginAnimations:context:方法跟 commitAnimations...
简单的转场动画,包括高仿QQ电话路径动画 CABasicAnimation动画等动画组合(想了解动画的童鞋可以研究研究)、常见的气泡转场动画(UIView动画,好多项目都在用哦)、以及翻页转场、模拟系统的导航、模态动画(对想...
Twinkle - ✨一个Swift和简单的方法能让任何UIView产生闪烁效果
NULL 博文链接:https://zhangmingwei.iteye.com/blog/1948108
UIView 个性弹窗 KLCPopup ,KLCPopup 是简单而灵活的,展示自定义弹窗 UIView 的类,带有各种动画效果,支持 iPh...
iOS 4.0之后,UIView新增了对Block的支持,现在只要使用简单的一个Block代码就可以在写动画的代码部分直接添加动画结束后的操作。还有就是在使用Notification 时候Block也非常有帮助。反正多用就可以体会到Block的...
JSKTimerView 是一个简单的自定义 UIView,充当独立的动画计时器。 以秒为单位设置计时器 启动计时器并让它自动动画 定时器的完全控制:启动、暂停、停止、重置和重置 手动设置计时器进度并相应地更新计时器 计时...
JTBorderDotAnimation JTBorderDotAnimation 是一个简单的动画,用于在 iOS 上围绕 UIView 旋转点。安装使用 ,将此行添加到您的 Podfile 中。 pod 'JTBorderDotAnimation', '~> 1.0'截图用法基本用法只需导入...
在开发过程中,对于动画效果,很多人好像都青睐于UIView动画,简单快捷,一个代码块能实现一个动画让很多其他系统下开发的小伙伴看红了眼。但是当有一些特殊的需求时,那你难免会有大量的Block嵌套产生,同时如何...