Dam*_*amo 5 objective-c uiview uigesturerecognizer caanimation ios
我有一系列UIViews,我沿着弧线动画.每个视图都有一个UIPanGestureRecognizer,它在任何动画发生之前按预期工作.
但是,在为视图设置动画后(使用下面的方法为视图的图层设置动画),手势无法按预期工作; 事实上,它似乎在原始屏幕位置工作.
我尝试了各种各样的事情,包括将视图框架和/或边界与动画图层上的视图框架和/或边界相匹配,甚至删除现有的手势并再次创建和添加它们(下面未显示).
如果有人知道发生了什么,或者可以让我在解决问题的道路上,我将不胜感激.
编辑: iMartin的改变建议
pathAnimation.removedOnCompletion = NO;
Run Code Online (Sandbox Code Playgroud)
至
pathAnimation.removedOnCompletion = YES;
Run Code Online (Sandbox Code Playgroud)
和
view.layer.position = ... //
Run Code Online (Sandbox Code Playgroud)
让我开始解决这个问题.
原始代码:
- (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;
}
}];
Run Code Online (Sandbox Code Playgroud)
}
您检查动画后视图/图层的框架吗?
我认为问题在于,所见并非所得。图层本身并没有改变它的位置/框架,但它只是presentationLayer改变了。表示层是您在屏幕上实际看到的内容。如果删除此行,您可以看到这一点:
pathAnimation.removedOnCompletion = NO; // Delete or set to YES
Run Code Online (Sandbox Code Playgroud)
设置此选项会NO导致表示层在屏幕上的位置与您的视图不同。
您应该做的是在向图层添加动画之前设置图层的最终位置。
view.layer.position = finalPosition; // You should calculate this
[view.layer addAnimation:pathAnimation forKey:@"arc"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
324 次 |
| 最近记录: |