应用CAKeyframeAnimation后的UIImageView框架原点

时间:2015-05-22 22:53:15

标签: rotation cgaffinetransform

我有一个UIImageView,我正在用CGAffineTransformRotate围绕一个圆圈移动。效果很好!但是当用户按下停止底部时,我想要UIImageView的实际x- / y-位置。到目前为止,我总是从创建UIImageView时获得原始的x- / y-值。

当用户停止旋转时,有没有办法获得实际位置?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案并分享,以防有人在运行类似的案例:

从UIBezierPath我使用边界信息,这给了我UIImageView停止的位置。代码如下:

UIBezierPath *path = [[UIBezierPath alloc] init];
[path addArcWithCenter:CGPointMake(iMiddleX, iMiddleY) radius:flR startAngle:degreesToRadians(flDegrees-0.01) endAngle:degreesToRadians(flDegrees) clockwise:YES];

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = 1;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
pathAnimation.duration = 1.0;

pathAnimation.path = path.CGPath;

NSInteger iX = path.bounds.origin.x;
NSInteger iY = path.bounds.origin.y;