【发布时间】:2013-09-18 22:40:32
【问题描述】:
我有一系列 UIView,我沿着弧线制作动画。每个视图上都有一个 UIPanGestureRecognizer,它在任何动画发生之前都会按预期工作。
但是,在为视图设置动画后(使用下面的方法为视图层设置动画),手势无法按预期工作;事实上,它们看起来好像在它们原来的屏幕位置上工作。
我尝试了各种方法,包括将视图框架和/或边界与动画层上的相匹配,甚至删除现有手势并再次创建和添加它们(未在下面显示)。
如果有人知道发生了什么或者可以让我解决问题,将不胜感激。
编辑: iMartin 的改变建议
pathAnimation.removedOnCompletion = NO;
到
pathAnimation.removedOnCompletion = YES;
和
view.layer.position = ... //
让我开始解决问题。
原代码:
- (void)animateUIViewAlongArc:(UIView*)view clockwise:(BOOL)clockwise duration:(float)duration
{
[UIView animateWithDuration:duration animations:^{
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.repeatCount = 1;
CGPoint viewCenter = view.objectCenter;
CGMutablePathRef arcPath = CGPathCreateMutable();
CGPathMoveToPoint(arcPath, NULL, viewCenter.x, viewCenter.y);
float angleOfRotation = self.angleIncrement;
if (clockwise == NO)
{
angleOfRotation *= -1.0f;
}
float fullwayAngle = view.angle + angleOfRotation;
CGPoint fullwayPoint = pointOnCircle(self.center, self.radius, fullwayAngle);
CGPathAddRelativeArc(arcPath, NULL, self.center.x, self.center.y, self.radius, view.angle, angleOfRotation);
pathAnimation.path = arcPath;
CGPathRelease(arcPath);
[view.layer addAnimation:pathAnimation forKey:@"arc"];
view.angle = fullwayAngle;
view.objectCenter = fullwayPoint;
} completion:^(BOOL finished){
if (finished)
{
CGRect frame = view.layer.frame;
CGRect bounds = view.layer.bounds;
view.frame = frame;
view.bounds = bounds;
}
}];
}
【问题讨论】:
标签: ios objective-c uiview uigesturerecognizer caanimation