iOS对象沿着指定路径进行动画 css3按指定路径动画

以下方法可作为两步实现:
以下方法在自定义view的类里面实现,可放在自定义函数中自行控制触法。也可放在drawRect或layoutSubviews里面让view在显示时触法。但推荐放在自定义view中触发,因为这样才可以做到自行控制,并保证同时只有一个在运行,否则会因为view的改变导致重绘,导致同时执行多个相同的动画,会影响效果和耗费内存。

一》让view对象沿指定的路径进行动画的方法:

以下是指定路径:
CAKeyframeAnimation *pathAnimation =[CAKeyframeAnimation animationWithKeyPath:@"position"];
//Set somevariables on the animation
pathAnimation.calculationMode =kCAAnimationPaced;
//We wantthe animation to persist - not so important in this case - but keptfor clarity
//If weanimated something from left to right - and we wanted it to stay inthe new position,
//then wewould need these parameters
pathAnimation.fillMode =kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 10;
//Lets loopcontinuously for the demonstration
pathAnimation.repeatCount = 10;

//Setup thepath for the animation - this is very similar as the code the drawthe line
//instead ofdrawing to the graphics context, instead we draw lines on aCGPathRef
//CGPointendPoint = CGPointMake(310, 450);
CGMutablePathRef curvedPath =CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, 10,10);
CGPathAddQuadCurveToPoint(curvedPath, NULL, 10,450, 310, 450);
CGPathAddQuadCurveToPoint(curvedPath, NULL, 310,10, 10, 10);

//Now wehave the path, we tell the animation we want to use this path -then we release the path
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);


在指定路径后,指定动画的对象,(在此用UIImageView举例:)
UIImageView*circleView = [[UIImageView alloc] initWithImage:circle];
circleView.frame = CGRectMake(1, 1, 40,40);
[selfaddSubview:circleView];

//Add theanimation to the circleView - once you add the animation to thelayer, the animation starts
[circleView.layeraddAnimation:pathAnimation
forKey:@"moveTheSquare"];

二>.若要把指定的路径以线条或其他方法显示出来,则要绘制路径,方法是:

UIGraphicsBeginImageContext(CGSizeMake(320,460));
CGContextRefctx = UIGraphicsGetCurrentContext();

//Setvariables in the context for drawing
CGContextSetLineWidth(ctx, 1.5);
CGContextSetStrokeColorWithColor(ctx, [UIColorwhiteColor].CGColor);

//Set thestart point of your drawing
CGContextMoveToPoint(ctx, 10, 10);
//The endpoint of the line is 310,450 .... i'm also setting a referencepoint of 10,450
//Aquadratic bezier curve is drawn using these coordinates -experiment and see the results.
CGContextAddQuadCurveToPoint(ctx, 10, 450, 310,450);
//Addanother curve, the opposite of the above - finishing back where westarted
CGContextAddQuadCurveToPoint(ctx, 310, 10, 10,10);

//Draw theline
CGContextDrawPath(ctx, kCGPathStroke);

若要绘制图片背景(直接添加即可),则:
//With theimage, we need a UIImageView
UIImage*image = [UIImage imagewithName:@"a.png"];
UIImageView*curveView = [[UIImageView alloc] image];
//Set theframe of the view - which is used to position it when we add it toour current UIView
curveView.frame = CGRectMake(1, 1, 320,460);
curveView.backgroundColor = [UIColorgreenColor];
[selfaddSubview:curveView];

iOS对象沿着指定路径进行动画 css3按指定路径动画

  

爱华网本文地址 » http://www.413yy.cn/a/25101015/262669.html

更多阅读

利用MapInfo进行缓冲区分析 缓冲区溢出漏洞利用

利用MapInfo进行缓冲区分析在进行缓冲区进行分析之前,首先了解一下缓冲区的概念。缓冲区是一种近似分析,围绕所选择地图对象的一个给定距离而产生的面积或区域。缓冲区是用户定义的,或者是对一组对象根据这些对象的属性值而产生的。结

第一实验学校升旗仪式程序及要求 升旗仪式要求

第一实验学校升旗仪式程序及要求一、入场退场及站队1、按照学校规定的升旗时间,按时整队有序进场,到达指定地点。退场时,待主持人宣布后进行,跑步按规定次序退场。进、退场做到迅速、安静、整齐。2、站队时,精神饱满,上下楼梯靠右行走,

U890成本核算遇到的问题及解决方法 成本核算方法有哪些

订单关闭、打开时点对取数影响取数之前关闭,在线盘点数量按零处理;重新打开,如果确实有在产,需要重新取数。在产品按材料倒挤,取数之前关闭,“全展”后材料全部分摊给完工产品;重新打开,如果确实有在产,需要重新“全展”。订单有在产成本时,手

声明:《iOS对象沿着指定路径进行动画 css3按指定路径动画》为网友一朝山水一朝臣分享!如侵犯到您的合法权益请联系我们删除