[英]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.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關鍵幀動畫路徑的函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.