Tag: cakeyframeanimation

dynamic修改CAKeyframeAnimation的持续时间

在我的代码中,我创build一个无限重复计数CAKeyframeanimation,将其添加到特定的CALayer。 我想在animation的同时修改animation的持续时间(=速度),而不需要重新启动我的animation。 所以当我点击一个button,我得到一个持续时间,我可以为animation设置。 我必须删除animation,创build另一个animation,并使其开始停止。 问题是,我似乎无法从这一点重新启动它,而没有从这一点做出循环。 如果是轮换,这不会有问题,但我使用翻译。 所以,我有3分,A,然后B,然后C,在一条直线上。 我的翻译从A到C,经过B,并且无限重复。 当我改变持续时间,在B点,我只能重build从B到C(这是不好的)翻译animation,或者,我可以重新创build一个animation从A到C与新的时间,但它重新从点A这也不好)。 你有什么想法,我怎么能做我想要的? 谢谢

EXC_BAD_ACCESS,同时使用CoreAnimation

我使用CoreAnimation来animationUIImageView(曲线贝塞尔animation)。 这里是我的代码: CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationCubic; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; CGPoint endPoint = originalPosition; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:star.layer.position]; [path addQuadCurveToPoint:endPoint controlPoint:CGPointMake(star.layer.position.x, endPoint.y)]; pathAnimation.path = path.CGPath; [star.layer addAnimation:pathAnimation forKey:@"moveToScorebarAnimation"]; 结果,我得到了stacktrace的EXC_BAD_ACCESS(code = 2,address = 0x0) : CoreGraphics`CG::Path::apply(void*, void (*)(void*, CGPathElementType, CGPoint const*)) const: 0x613c06: pushl %ebp 0x613c07: movl […]

animation时更新视图的框架

我正在做这样的animation: CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; animation.duration = 100.0; animation.path = self.animationPath.CGPath; [view.layer addAnimation:animation forKey:@"animation"]; 工作正常,但是,现在尝试检测在屏幕上移动的对象的触摸时失败: – (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { for (UIView* subview in self.subviews ) { if ( [subview hitTest:[self convertPoint:point toView:subview] withEvent:event] != nil ) { [self handleTap]; return YES; } } return NO; } 它失败了,因为视图的框架不再是它在animation时在屏幕上的明显位置。 我怎样才能让pointInside与正在animation的视图一起工作?

iOS的CAKeyFrameAnimation缩放在animation结束的闪烁

在关键帧animation的另一个testing中,我将沿着theImagepath移动UIImageView(称为theImage ),并在移动时将其放大,从而在path的末端产生两倍大的图像。 我最初的代码是通过这些元素来启动animation: UIImageView* theImage = …. float scaleFactor = 2.0; …. theImage.center = destination; theImage.transform = CGAffineTransformMakeScale(1.0,1.0); CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"]; [resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(theImage.image.size.height*scaleFactor, theImage.image.size.width*scaleFactor)]]; resizeAnimation.fillMode = kCAFillModeBackwards; resizeAnimation.removedOnCompletion = NO; CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.path = [jdPath path].CGPath; pathAnimation.fillMode = kCAFillModeBackwards; pathAnimation.removedOnCompletion = NO; CAAnimationGroup* group = [CAAnimationGroup animation]; group.animations = […]

CAKeyframeAnimation手动进度

我有一个UIView的背景层有一个简单的直线pathCAKeyframeAnimation设置为其“path”。 我可以让animation“冻结”,也就是说,手动改变它的进度? 例如:如果path长度为100个点,则将进度(偏移量?)设置为0.45应使视图向下移动45个点。 我记得看到一篇文章,通过CAMediaTiming接口做了类似的事情(沿着一个基于滑块的值的path移动一个视图),但是我还没有find它,即使经过了几个小时的search。 如果我以完全错误的方式接近这一点,请让我知道。 谢谢。 这里有一些示例代码,如果以上不够清楚。 – (void)setupAnimation { CAKeyFrameAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:_label.layer.position]; [path addLineToPoint:(CGPoint){200, 200}]; animation.path = path.CGPath; animation.duration = 1; animation.autoreverses = NO; animation.removedOnCompletion = NO; animation.speed = 0; // _label is just a UILabel in a storyboard [_label.layer addAnimation:animation forKey:@"LabelPathAnimation"]; } – (void)sliderDidSlide:(UISlider […]

我可以animation的UIScrollView contentOffset属性通过它的图层?

我想用CGPathRef来缩放和滚动一个UIScrollView。 正因为如此,我假设我必须animationUIScrollView的图层属性? 但是,我会animation哪些属性,使其相当于做一个UIViewanimation,并设置其contentOffset属性和zoomScale? 这些不是CALayer的属性。 任何想法,我将如何处理这个? 同样,只需要将scrollview移动到某个contentOffset和zoomScale,但不一定是线性的从A点到B点,A放大到B点。 我正在想一个CAKeyFrameAnimation与CGPathRef,但我不知道哪些属性animation。

UIImageView上的iOS CAKeyframeAnimation rotationMode

我正在试验沿着贝塞尔path移动的UIImageView对象位置的关键帧animation。 此图显示了animation之前的初始状态。 蓝线是path – 最初是直线向上移动,浅绿色的框是最初的边界框或图像,深绿色的“鬼”是我正在移动的图像: 当我将rotationMode设置为nil下启动animation时,图像始终保持与预期一样的方向。 但是,当我使用rotationMode设置为kCAAnimationRotateAuto来kCAAnimationRotateAutoanimation时,图像将立即逆时针旋转90度,并始终保持此方向通过path。 当它到达path的末端时,它会以正确的方向重新绘制(它实际上显示了我重新定位到最终位置的UIImageView) 我天真地期望rotationMode将图像定位到path的正切,而不是正常,特别是当Apple文档为CAKeyframeAnimation rotationMode状态 确定沿pathanimation的对象是否旋转以匹配path切线。 那么这里的解决scheme是什么? 我是否需要将图像顺时针旋转90度? 还是有什么我失踪? 谢谢你的帮助。 编辑3月2日 我在pathanimation之前使用仿射旋转添加了一个旋转步骤,如下所示: theImage.transform = CGAffineTransformRotate(theImage.transform,90.0*M_PI/180); 然后在pathanimation之后,重置旋转: theImage.transform = CGAffineTransformIdentity; 这使得图像以预期的方式跟随path。 不过,我现在遇到了图像闪烁的另一个问题。 我已经在这个SO问题中寻找闪烁问题的解决scheme: animation结束时,iOS CAKeyFrameAnimation缩放闪烁 所以现在我不知道我是做得更好还是更糟! 3月12日编辑 虽然迦勒指出是的,我不得不预先旋转我的形象,罗布提供了一个很好的代码包,几乎完全解决了我的问题。 Rob唯一没有做的就是补偿我的资产是以垂直方向而不是水平方向绘制的,因此在做animation之前还需要将它们预先旋转90度。 但是,嘿,唯一公平的是我必须做一些工作才能使事情顺利进行。 所以我对Rob的解决scheme进行了一些细微的修改以适应我的要求: 当我添加UIView时,我预先旋转它来抵消通过设置rotationMode添加的固有rotationMode : theImage.transform = CGAffineTransformMakeRotation(90 * M_PI / 180.0); 我需要在animation结束时保持这个旋转,所以我没有在完成块被定义之后用新的比例因子对视图的变换进行爆破,而是基于当前的变换构build比例: theImage.transform = CGAffineTransformScale(theImage.transform,scaleFactor,scaleFactor); 这就是我所需要做的就是让自己的形象像我期望的那样走上去! 3月22日编辑 我刚刚上传到GitHub上的一个演示项目,展示了一个沿着贝塞尔path移动的对象。 代码可以在PathMove中find 我还在我的博客中写过关于在iOS中沿着贝塞尔path移动对象的问题

animation期间无法获取CALayer的当前位置

我试图实现一个animation,当你按下一个button时,它将animation块放下,当你释放时,它将animation恢复到原来的位置,但无论如何我都无法获得animation块的当前位置。 这是我的代码: -(IBAction)moveDown:(id)sender{ CGRect position = [[container.layer presentationLayer] frame]; [movePath moveToPoint:CGPointMake(container.frame.origin.x, position.y)]; [movePath addLineToPoint:CGPointMake(container.frame.origin.x, 310)]; CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; moveAnim.path = movePath.CGPath; moveAnim.removedOnCompletion = NO; moveAnim.fillMode = kCAFillModeForwards; CAAnimationGroup *animGroup = [CAAnimationGroup animation]; animGroup.animations = [NSArray arrayWithObjects:moveAnim, nil]; animGroup.duration = 2.0; animGroup.removedOnCompletion = NO; animGroup.fillMode = kCAFillModeForwards; [container.layer addAnimation:animGroup forKey:nil]; } -(IBAction)moveUp:(id)sender{ CGRect position […]

CoreAnimation – 不透明度淡入和淡出animation不工作

我正在试图创build一个相当简单的CoreAnimation在AVComposition使用。 我的目标是创build一个CALayer ,通过各个子层,淡入淡出标题,然后淡入淡出图像。 幻灯片,基本上。 这是使用AVAssetWriter导出到.mov。 在WWDC 2011 AVEditDemo的帮助下,我已经能够得到一个标题和图像出现。 问题是他们都在同一时间在屏幕上! 我创build了不透明度为0.0的每个图层。 然后我使用下面的代码添加了一个CABasicAnimation使它们从0.0到1.0淡出: CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeInAnimation.fromValue = [NSNumber numberWithFloat:0.0]; fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0]; fadeInAnimation.additive = NO; fadeInAnimation.removedOnCompletion = YES; fadeInAnimation.beginTime = 1.0; fadeInAnimation.duration = 1.0; fadeInAnimation.fillMode = kCAFillModeForwards; [titleLayer addAnimation:fadeInAnimation forKey:nil]; 问题似乎是“beginTime”属性。 “1.0”意味着延迟,所以从animation开始1秒后开始。 但是,它直接出现在屏幕上。 淡出animation 这个代码的反面,淡出,只是简单地将fromValue更改为1.0,toValue更改为0.0。 它有一个开始时间4.0和完美的作品。 我正在使用以下来创buildanimatedTitleLayer : CATextLayer *titleLayer = [CATextLayer layer]; […]

当uiscrollview事件发生时,NSTimer不会被触发

我有一个UIImageView放置在UIScrollView,基本上这个UIImageView拥有非常大的地图,并创build了一个预定义的path与“箭头”指向导航方向的animation。 但是,每当uiscrollevents发生,我认为MainLoop冻结和NSTimer不被解雇,animation停止。 在UIScrollView,CAKeyFrameAnimation或NSTimer中是否有解决这个问题的现有属性? //viewDidLoad self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(drawLines:) userInfo:nil repeats:YES]; – (void)drawLines:(NSTimer *)timer { CALayer *arrow = [CALayer layer]; arrow.bounds = CGRectMake(0, 0, 5, 5); arrow.position = CGPointMake(line.x1, line.y1); arrow.contents = (id)([UIImage imageNamed:@"arrow.png"].CGImage); [self.contentView.layer addSublayer:arrow]; CAKeyframeAnimation* animation = [CAKeyframeAnimation animation]; animation.path = path; animation.duration = 1.0; animation.rotationMode = kCAAnimationRotateAuto; // object auto rotates […]