微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在iPhone中使用CALayer和CGPath的动画期间如何获取位置

如何解决在iPhone中使用CALayer和CGPath的动画期间如何获取位置

||
 hI,I am workng on animation using CALayer and CAPath.

 Here I am animating an Image from top to bottom of screen.I gave starting and ending position for
 the animation.Now,I want to get position  during the animation.

Sample Code:

   - (void)onTimer
    {

    CGImageRef imageRef = [[UIImage imageNamed:@\"apple.png\"] CGImage];
int startX                      = round(random() % 460);
double speed     = 1 / round(random() %100) + 1.0;

layer          = [CALayer layer];
layer.name              = @\"layer\";
layer.contents          = (id)imageRef; // cached image
layer.frame             = CGRectMake(startX,self.view.frame.size.height+10,CGImageGetWidth(imageRef),CGImageGetHeight(imageRef));

[mView.layer addSublayer:layer];


 path = CGPathCreateMutable(); 
CGPathMovetoPoint(path,NULL,startX,-100);
CGPathAddLinetoPoint(path,self.view.frame.size.height+10);



CAKeyframeAnimation *animation= [CAKeyframeAnimation animationWithKeyPath:@\"position\"];

animation.delegate=self;

animation.duration= 10*speed;
animation.autoreverses=NO;
animation.path=path;
animation.repeatCount = 0;
animation.removedOnCompletion=YES;
animation.calculationMode = kCAAnimationLinear;

[layer addAnimation:animation forKey:@\"position\"];


CGPoint point= CGPathGetCurrentPoint(path);


   }

    In this I used \"CGPathGetCurrentPoint\" method but it did not work. Also used 
     presentationLayer method of CALayer but uit also did not work in this case.

     Can anyone suggest the code to get the position during animation
    thanks in advance

解决方法

通过查看图层的presentationLayer上的属性,可以获得动画期间在屏幕上看到的内容的值。,核心动画不是为此设计的。它的工作是为您处理属性动画,而不是让您接触它。 如果您想知道动画在动画中的位置,那么您需要在没有Core Animation的情况下自己制作所有动画。
CGPathGetCurrentPoint()
是访问
CGPath
实例的控制点而不是Core Animation关键帧动画路径的函数。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。