IOS当前关键帧y轴

IOS当前关键帧y轴,ios,objective-c,Ios,Objective C,嘿,我试图在imageview移动时显示它的y轴,但它没有显示动画y轴,它只显示一个数字 //LINE ANAMATION CALayer *layer = line.layer; CGPoint startPoint = (CGPoint){line.center.x,20}; CGPoint endPoint = (CGPoint){line.center.x, screenSizeY/2}; CGMutablePathRef thePath = CGPathCreateMutable()

嘿,我试图在imageview移动时显示它的y轴,但它没有显示动画y轴,它只显示一个数字

//LINE ANAMATION
CALayer *layer = line.layer;
CGPoint startPoint = (CGPoint){line.center.x,20};
CGPoint endPoint = (CGPoint){line.center.x, screenSizeY/2};

CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint(thePath, NULL, startPoint.x, startPoint.y);
CGPathAddLineToPoint(thePath, NULL, endPoint.x, endPoint.y);

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.duration = 3.f;
animation.path = thePath;
animation.autoreverses = YES;
animation.repeatCount = INFINITY;
[layer  addAnimation:animation forKey:@"position"];
NSLog(@"%f", line.center.y);

这有几个问题。首先,动画状态保持在表示层中。视图和基础层将立即反映动画的最终状态。其次,您的
NSLog
语句将只被调用一次,因为您不在循环中

如果要在动画的每一帧执行某些操作,则需要在每一帧上获得回调。在此回调中,您可以通过查看表示层来检查当前Y位置:

- (void)myCallback:(CADisplayLink *)link
{
    NSLog(@"%f", CGRectGetMidY(line.layer.presentationLayer.frame));
}

我试图在动画移动时获取y轴,因此nslog应继续显示不同的y值。我是objective-c新手,您是否认为您可以编辑我提供的代码并解释更改的内容,以便我理解。谢谢你的帮助。