1.过渡动画 CATransition
CATransition *animation = [CATransition animation]; [animation setDuration:1.0]; [animation setType:kCATransitionFade]; [animation setSubtype:kCATransitionFromLeft]; [_imgPic.layer addAnimation:animation forKey:nil];
说明:
(1).Duration 延迟
(2).Type
kCATransitionFade // 交叉淡化过渡(不支持过渡方向)
kCATransitionMoveIn // 新视图移到旧视图上面
kCATransitionPush // 新视图把旧视图推出去
kCATransitionReveal // 将旧视图移开,显示下面的新视图
cube // 立方体翻滚效果
oglFlip // 上下左右翻转效果
suckEffect // 收缩效果,如一块布被抽走(不支持过渡方向)
rippleEffect // 滴水效果(不支持过渡方向)
pageCurl // 向上翻页效果
pageUnCurl // 向下翻页效果
cameraIrisHollowOpen // 相机镜头打开效果(不支持过渡方向)
cameraIrisHollowClose // 相机镜头关上效果(不支持过渡方向)
2.路径动画 CAKeyframeAnimation
CAKeyframeAnimation *ani=[CAKeyframeAnimation animation]; CGMutablePathRef aPath=CGPathCreateMutable(); CGPathMoveToPoint(aPath, nil, 20, 20); CGPathAddCurveToPoint(aPath, nil, 20, 40, 220, 40, 240, 380); ani.path=aPath; ani.duration=10; ani.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; ani.rotationMode=@"autoReverse"; [redView.layer addAnimation:ani forKey:@"position"];
//特殊曲线 贝塞尔曲线
//贝塞尔曲线路径 UIBezierPath *movePath = [UIBezierPath bezierPath]; [movePath moveToPoint:CGPointMake(0.0, 0.0)]; [movePath addQuadCurveToPoint:CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0) controlPoint:CGPointMake(self.view.frame.size.width, self.view.frame.size.height)];
说明:(1).moveToPoint :动画起始位置
(2).轨迹
- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;
//endPoint 完成位置 controllerPoint 轨迹中的位置
3.基本类型 CABasicAnimation 事例
//背景色动画 CABasicAnimation *animation=[CABasicAnimation animation]; //设置颜色 animation.toValue=(id)[UIColor blueColor].CGColor; //动画时间 animation.duration=1; //是否反转变为原来的属性值 animation.autoreverses=YES; //把animation添加到图层的layer中,便可以播放动画了。forKey指定要应用此动画的属性 [self.view.layer addAnimation:animation forKey:@"backgroundColor"]; //缩放动画 CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"]; scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]; scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; scaleAnim.removedOnCompletion = YES; //透明动画 CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"]; opacityAnim.fromValue = [NSNumber numberWithFloat:1.0]; opacityAnim.toValue = [NSNumber numberWithFloat:0.1]; opacityAnim.removedOnCompletion = YES;
时间: 2024-12-29 12:12:49