动画杂记

来源:互联网 发布:淘宝靠谱的三星手机店 编辑:程序博客网 时间:2024/06/07 17:53
画圆:
1.在UIView的基础上:

UIGraphicsBeginImageContext(CGSizeMake(320,460)); 

CGContextRef ctx = UIGraphicsGetCurrentContext(); 

CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);    

CGContextAddArc(ctx, 160, 240, 100, 0, 2*M_PI, 1); 

CGContextDrawPath(ctx, kCGPathStroke); 

UIImage *curve = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext();        

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];    

imageView.image = curve;

[self addSubview:imageView];

2.使用UIBezierPath

UIBezierPath *patha=[UIBezierPath bezierPath];        

CGRect recta=[UIScreen mainScreen].applicationFrame;        

[patha addArcWithCenter:CGPointMake(recta.size.width/2,recta.size.height/2-130) radius:65 startAngle:0 endAngle:2*M_PI clockwise:NO];    

CAShapeLayer *arcLayera=[CAShapeLayer layer];    

arcLayera.path=patha.CGPath;//46,169,230    

arcLayera.fillColor=[UIColor whiteColor].CGColor;    

arcLayera.strokeColor=[UIColor grayColor].CGColor;    

arcLayera.lineWidth=2;    

arcLayera.frame=self.view.frame;   

[self.view.layer addSublayer:arcLayera];

使uiimageView转动的轨迹为圆(围绕固定点转动)
//初始化ImageView(我这儿是使用UIbeziePath画了一个圆点)

IImageView *circleView1 = [[UIImageView alloc] init];    

[circleView1.layer addSublayer:arcLayer];    

[self.view addSubview:circleView1];    

circleView1.frame = CGRectMake(recta.size.width/2,recta.size.height/2-130, 30, 30);    

//设置动画的属性    

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];      pathAnimation.calculationMode = kCAAnimationPaced;      

pathAnimation.fillMode = kCAFillModeForwards;      

pathAnimation.removedOnCompletion = NO;      

pathAnimation.duration = 0.5;      

pathAnimation.repeatCount = 1000;    

//设置运转动画的路径    

CGMutablePathRef curvedPath = CGPathCreateMutable();    

CGPathAddArc(curvedPath, NULL, recta.size.width/2+15,recta.size.height/2-115, 62, M_PI / 8, M_PI / 8 + 2 * M_PI, 0);    

pathAnimation.path = curvedPath; CGPathRelease(curvedPath);    

//给UIImageVIew添加旋转轨迹

[circleView1.layer addAnimation:pathAnimation forKey:@"moveTheCircleOne"];
0 0
原创粉丝点击