1.
CGMutablePathRef starPath = CGPathCreateMutable();
CGPathMoveToPoint(starPath,NULL,100.0f, 100.0f);
CGPathAddLineToPoint(starPath, NULL, 100.0f, 280.0f);
CGPathAddLineToPoint(starPath, NULL, 260.0, 170.0);
CGPathAddLineToPoint(starPath, NULL, 60.0, 170.0);
CGPathAddLineToPoint(starPath, NULL, 220.0, 280.0);
CGPathCloseSubpath(starPath);//记得这一点
2.关键帧动画
1>关于位置
<CAAnimationDelegate>//如果监听动画的执行过程就要设置代理
CAKeyframeAnimation *animation = nil;
animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[animation setDuration:10.0f];
[animation setDelegate:self];
[animation setPath:starPath];
CFRelease(starPath);//记得这一点
starPath = nil;
[[imageView layer] addAnimation:animation forKey:@"position"];
//比如监听动画执行完了
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
}
2>关于透明度
CAKeyframeAnimation *opAnim = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
opAnim.duration = 6.0;
opAnim.values =[NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.25],
[NSNumber numberWithFloat:0.75],
[NSNumber numberWithFloat:1.0],
nil];
opAnim.keyTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:1.0], nil];
[view.layer addAnimation:opAnim forKey:@"animateOpacity"];
3.基本动画
1>关于透明度
CABasicAnimation *opAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
opAnim.duration = 2.0;
opAnim.fromValue = [NSNumber numberWithFloat:.20];
opAnim.toValue= [NSNumber numberWithFloat:1.0];
opAnim.cumulative = YES;
opAnim.repeatCount = 2;
[view.layer addAnimation:opAnim forKey:@"animateOpacity"];
2>关于控件的大小位置的
CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(180, 200);
CABasicAnimation *moveAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
moveAnim.duration = 6.0;
moveAnim.toValue= [NSValue valueWithCATransform3D:
CATransform3DMakeAffineTransform(moveTransform)];
[view.layer addAnimation:moveAnim forKey:@"animateTransform"];
3.首尾动画
1>.
[UIView beginAnimations:nil context:NULL];
CGAffineTransform moveTransform = CGAffineTransformMakeTranslation(180, 200);
view.layer.affineTransform=moveTransform;
[UIView commitAnimations];
2>.
[UIView beginAnimations:@"animationID" context:nil];
[UIView setAnimationDuration:1.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
[UIView setAnimationDidStopSelector:@selector(viewAnimationDone:)];//类似上面的代理监听动画的完成
[UIView commitAnimations];
原文:http://www.cnblogs.com/chaoyueME/p/6272372.html