Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIView层设置动画后,UIView上的UIPangEstureRecognitor行为异常_Ios_Objective C_Uiview_Uigesturerecognizer_Caanimation - Fatal编程技术网

Ios UIView层设置动画后,UIView上的UIPangEstureRecognitor行为异常

Ios UIView层设置动画后,UIView上的UIPangEstureRecognitor行为异常,ios,objective-c,uiview,uigesturerecognizer,caanimation,Ios,Objective C,Uiview,Uigesturerecognizer,Caanimation,我有一系列的UIView,我沿着一条弧设置动画。每个视图上都有一个UIPangestureRecognitor,它在任何动画出现之前都能正常工作 但是,在设置视图动画(使用下面设置视图层动画的方法)后,手势无法按预期工作;事实上,它们似乎在原来的屏幕位置上工作 我尝试了各种方法,包括将视图帧和/或边界与动画层上的匹配,甚至删除现有的手势并再次创建和添加它们(下面未显示) 如果有人知道发生了什么,或者能让我解决这个问题,我将不胜感激 编辑:iMartin的更改建议 pathAnimation.re

我有一系列的UIView,我沿着一条弧设置动画。每个视图上都有一个UIPangestureRecognitor,它在任何动画出现之前都能正常工作

但是,在设置视图动画(使用下面设置视图层动画的方法)后,手势无法按预期工作;事实上,它们似乎在原来的屏幕位置上工作

我尝试了各种方法,包括将视图帧和/或边界与动画层上的匹配,甚至删除现有的手势并再次创建和添加它们(下面未显示)

如果有人知道发生了什么,或者能让我解决这个问题,我将不胜感激

编辑:iMartin的更改建议

pathAnimation.removedOnCompletion = NO;

让我走上解决问题的道路

原始代码:

- (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;
        }
    }];

}

在动画之后是否检查了视图/层的帧

我认为问题在于,你所看到的不是你所得到的图层本身没有改变其位置/帧,只是它的
presentationLayer
改变了位置/帧。
显示层是您在屏幕上实际看到的。如果删除此行,则可以看到以下内容:

pathAnimation.removedOnCompletion = NO; // Delete or set to YES
将此设置为
NO
会导致演示层在屏幕上的位置与您的视图不同。
您应该做的是在向层添加动画之前设置层的最终位置

view.layer.position = finalPosition; // You should calculate this
[view.layer addAnimation:pathAnimation forKey:@"arc"];
pathAnimation.removedOnCompletion = NO; // Delete or set to YES
view.layer.position = finalPosition; // You should calculate this
[view.layer addAnimation:pathAnimation forKey:@"arc"];