问题描述
我是pretty肯定,这是一个曾经尝试过这个人相当简单明了的问题,但我是怎样的一个新手,你叫什么先进的动画。
我试图用CAKeyframeAnimation(与位置键路径)
要创建一个对象的下列运动我试过用UIBezierPath设置路径,但得到了与没有找到它:)
背后的逻辑困惑和沮丧pretty快我很想听听你对此的看法...
这是我的基本code(这还不如从头开始编写,如果将发生一个更好的主意:P)
此外,我想淡出在完成的对象。有没有这样的动画完成后进行选择? (如[UIView的animateWithDuration])?
UIBezierPath * thumbPath = [UIBezierPath bezierPath]
[thumbPath moveToPoint:P(99270)];
[thumbPath addCurveToPoint:P(164260)controlPoint1:P(164280)controlPoint2:P(164280)];
[thumbPath addCurveToPoint:P(164260)controlPoint1:P(260310)controlPoint2:P(260310)];CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@位置];
pathAnimation.path = thumbPath.CGPath;
pathAnimation.duration = 2.0;
只是想分享我已经找到了这样做,任何人谁是CAAnimation一个noob像我这样的最简单的方法。
,而不是使用一个UIBezierPath的,我刚手写在屏幕上(X,Y)的路径的点,并使用这些比创建的路径,因此产生所需的曲线。非常有用和容易。
希望对您有所帮助:
的NSArray * myPoints = [NSArray的arrayWithObjects:
[NSValue valueWithCGPoint:P(77287)]
[NSValue valueWithCGPoint:P(97270)]
[NSValue valueWithCGPoint:P(112260)]
[NSValue valueWithCGPoint:P(130,250)],
[NSValue valueWithCGPoint:P(154245)]
[NSValue valueWithCGPoint:P(174250)]
[NSValue valueWithCGPoint:P(193260)]
[NSValue valueWithCGPoint:P(210270)]
[NSValue valueWithCGPoint:P(231287)]
零];CGMutablePathRef路径= CGPathCreateMutable();
CGPathMoveToPoint(路径,NULL,77,280);对于(NSValue * VAL在myPoints){
CGPoint P = [VAL CGPointValue]
CGPathAddLineToPoint(路径,NULL,p.x,p.y);
}CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@位置];
pathAnimation.path =路径;
CGPathRelease(路径);
I'm pretty sure this is a rather simple and straightforward question for anyone that has ever tried this before , but i'm kind of a newbie to what you would call "advanced" animation.
I'm trying to create the following movement of an object by using CAKeyframeAnimation (with "position" key path)
I've tried setting the path with a UIBezierPath but got confused and frustrated pretty fast with not finding the logic behind it :)
I'd love to hear if you have an opinion about this...
This is my base code (which might as well be written from scratch if a better idea would occur :P)
Also i wanted to fade out the object on completion. is there such a selector that performs on animation completion? (such as [UIView animateWithDuration] ) ?
UIBezierPath *thumbPath = [UIBezierPath bezierPath];
[thumbPath moveToPoint: P(99,270)];
[thumbPath addCurveToPoint:P(164,260) controlPoint1:P(164,280) controlPoint2:P(164,280)];
[thumbPath addCurveToPoint:P(164,260) controlPoint1:P(260,310) controlPoint2:P(260,310)];
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.path = thumbPath.CGPath;
pathAnimation.duration = 2.0;
Just wanted to share the simplest way i've found for doing this, for anyone who is a noob in CAAnimation such as myself.
Instead of using a UIBezierPath , i've just manually written the points on screen (x,y) for the path, and than created a path using those, thus creating the needed curve. Very useful and easy.
Hope you find this helpful:
NSArray *myPoints = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:P(77,287)],
[NSValue valueWithCGPoint:P(97,270)],
[NSValue valueWithCGPoint:P(112,260)],
[NSValue valueWithCGPoint:P(130,250)],
[NSValue valueWithCGPoint:P(154,245)],
[NSValue valueWithCGPoint:P(174,250)],
[NSValue valueWithCGPoint:P(193,260)],
[NSValue valueWithCGPoint:P(210,270)],
[NSValue valueWithCGPoint:P(231,287)],
nil];
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 77, 280);
for(NSValue *val in myPoints){
CGPoint p = [val CGPointValue];
CGPathAddLineToPoint(path, NULL, p.x, p.y);
}
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.path = path;
CGPathRelease(path);
这篇关于iOS的UIBezierAnimation曲线了,如何来建立某种形式的弧线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!