五角星轨迹

pragma mark**** 使用路径**
**
- (void)pageButtonClick:(UIButton*)button{
// 设置按钮不可见
button.alpha = 0.0;
// 创建路径
CGMutablePathRefstarPath =CGPathCreateMutable();
CGPathMoveToPoint(starPath,NULL,160,100);
CGPathAddLineToPoint(starPath,NULL,100,280);
CGPathAddLineToPoint(starPath,NULL,260,170);
CGPathAddLineToPoint(starPath,NULL,60,170);
CGPathAddLineToPoint(starPath,NULL,220,280);
//闭合路径
CGPathCloseSubpath(starPath);
//创建位置变化的帧动画
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//设置动画的持续时间
animation.duration=10.0;
//设置self为动画委托对象
animation.delegate=self;
//设置动画路径
animation.path= starPath;
//释放动画路径对象
CFRelease(starPath);
[self.imageView.layeraddAnimation:animationforKey:@"position"];}
pragma mark **** CAAnimationDelegate**
//动画开始方法
-**
-(void)animationDidStart:(CAAnimation *)anim{
NSLog(@"动画开始。。。。");
}
**
//动画结束方法
-
(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
NSLog(@"动画结束。。。");
[UIView animateWithDuration:1.0 animations:^{
button.alpha=1.0;
}];
}
关键帧动画

pragma mark**** 关键帧动画**
//创建opacity的关键帧动画
CAKeyframeAnimation *opAnim2 = [CAKeyframeAnimation animationWithKeyPath:@"opacity2"];
//设置动画持续时间
opAnim2.duration=6.0;
//设置关键帧时间点
opAnim2.keyTimes=@[@0.0,@0.5,@1];
//设置每个关键帧上的opacity值
opAnim2.values=@[@0.25,@0.75,@1.0];
//设置动画结束时的处理方式
opAnim2.fillMode = kCAFillModeForwards;
//设置动画结束时是否停止
opAnim2.removedOnCompletion = NO;
//添加动画到层
[self.imageView.layeraddAnimation:opAnim2forKey:@"animateOpacity2"];
//创建平移仿射变换
CGAffineTransform moveTransfrom3 = CGAffineTransformMakeTranslation(200, 300);
//创建平移动画
CABasicAnimation *moveAnim2 = [CABasicAnimation animationWithKeyPath:@"transform"];//@"transform"换成别的不好用
moveAnim2.duration=6.0;
//设置结束位置
moveAnim2.toValue = [NSValue valueWithCATransform3D:(CATransform3DMakeAffineTransform(moveTransfrom3))];
moveAnim2.fillMode = kCAFillModeForwards;
moveAnim2.removedOnCompletion = NO;
[self.imageView.layeraddAnimation:moveAnim2forKey:@"animateTransform2"];
显式动画

//创建opacity动画
CABasicAnimation *opAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
//设置动画持续时间
opAnim.duration = 3.0;
//设置opcity开始值
opAnim.fromValue=@0.25;//0.25为NSNumber对象
//设置oppacity结束值
opAnim.toValue =@1.0;
//设置累计上次值
opAnim.cumulative = YES;
//设置动画重复2次
opAnim.repeatCount = 2;
//设置动画结束时的处理方式
opAnim.fillMode = kCAFillModeForwards;
//设置动画结束时是否停止
opAnim.removedOnCompletion = YES;
//添加动画到层
[self.imageView.layer addAnimation:opAnim forKey:@"animateOpacity"];
//创建平移仿射变量
CGAffineTransform moveTransform2 = CGAffineTransformMakeTranslation(200, 300);
//创建平移动画
CABasicAnimation *moveAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
moveAnim.duration = 6.0;
//设置结束位置
moveAnim.toValue = [NSValue valueWithCATransform3D:(CATransform3DMakeAffineTransform(moveTransform2 ))];
moveAnim.fillMode = kCAFillModeForwards;
moveAnim.removedOnCompletion = NO;
[self.imageView.layer addAnimation:moveAnim forKey:@"animateTransform"];
隐式动画
self.imageView.layer.opacity = 0.25;
//创建平移仿射变换
CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(200, 300);
//将仿射变换作用于plane视图上的层
self.imageView.layer.affineTransform= moveTransform;
//设置层的opacity属性
self.imageView.layer.opacity = 1;
pragma mark**** 隐士动画**
//创建平移仿射变换
CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(200, 300);
//将仿射变换作用于plane视图上的层
self.imageView.layer.affineTransform= moveTransform;
//设置层的opacity属性
self.imageView.layer.opacity = 1;
网友评论