1,首先,在iOS中,动画有2种,一种是对 UIView 作动画处理,另外一种是对 CALayer作动画。html
这里咱们先要搞清楚 UIView 与 CALayer 之间的关系,UIView 是界面的基础元素,是根据CoreAnimation 来绘制的,UIView 有个 layer 属性,每一个uiview 都有个layer 层,也能够在layer 上添加其余 layer 层。iview
下面这段是对 uiview 的动画:动画
CGContextRef context = UIGraphicsGetCurrentContext(); // 获取图形上下文 [UIView beginAnimations:nil context:context]; // 开始动画 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //开始和结束时动画效果比较慢,枚举四种过渡效果 [UIView setAnimationDuration:2.0]; //动画持续时间 [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(viewFadeOut)]; // 动画结束后执行 [imageview setAlpha:1.0f]; [UIView commitAnimations]; // 动画完成
setAnimationWillStartSelectorui
动画即将开始执行
下面是做用于 layer 层的动画:spa
CATransition *animation = [CATransition animation];3d
[animation setDuration:2.0f];code
[animation setTimingFunction:[CAMediaTimingFunctionhtm
functionWithName:kCAMediaTimingFunctionEaseIn]];animation
[animation setType:kCATransitionReveal];it
[animation setSubtype: kCATransitionFromTop];
[self.view.layer addAnimation:animation forKey:@"animation"];
setDuration:和UIView中的动画效果同样,持续时间.
setTimingFunction:是动画的种类,和UIView同样,好比匀速动画,快速开始结束等.
setType:是指定动画的类型,他有: