开发者

How to get position during animation which uses CALayer and CGPath in iPhone

 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, NULL, startX, 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.r开发者_运维问答emovedOnCompletion=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


You can get the value of what you see on the screen during an animation by looking at the properties on the layer's presentationLayer.


Core Animation was not designed for this. Its job is to handle property animation for you, not expose you to it.

If you want to know its position during animation, then you'll need to do all the animation yourself without Core Animation.

CGPathGetCurrentPoint() is a function that accesses control points of CGPath instances, not Core Animation keyframe animation paths.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜