1
的我画四分之一圆。为此,我用UIView的中心作为中心。绘图部分很好。
现在我想让它在路径上动画。所以我使用了KeyFrame动画。
问题是它在CAShapeLayer的中心旋转。我不想要。我想围绕边界旋转cgpath。在初始位置看,这是正确的。但是当开始在路径上旋转时,它正在占据CAShapeLayer的中心,然后在路径上旋转。路径动画CAShapeLayer
这里是黄季代码:
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100, (0), (M_PI_2), NO);
CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100-50, (M_PI_2), (0), YES);
CGPathCloseSubpath(path);
CAShapeLayer* arcLayer = [[CAShapeLayer alloc]init];
arcLayer.path = path;
arcLayer.frame = CGPathGetPathBoundingBox(path);
arcLayer.fillColor = [UIColor yellowColor].CGColor;
arcLayer.backgroundColor = [UIColor whiteColor].CGColor;
arcLayer.bounds = CGPathGetPathBoundingBox(path);
我盯着单水龙头动画gesture.Here是动画代码:
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{
CGPoint touchPoint=[gesture locationInView:self];
NSArray* subLayerArray = [pathLayer sublayers];
for (int i = 0; i < subLayerArray.count; i++) {
CAShapeLayer* layer = [subLayerArray objectAtIndex:i];
if(CGPathContainsPoint(layer.path, NULL, touchPoint, NO)){
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, self.bounds.size.width/2, self.bounds.size.height/2, 100, 0, 3*M_PI/2, NO);
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
anim.path = path;
anim.rotationMode = kCAAnimationRotateAutoReverse;
anim.fillMode = kCAFillModeForwards;
anim.removedOnCompletion = NO;
anim.duration = 100.0;
[layer addAnimation:anim forKey:@""];
}
}
}
不要再问同样的问题。如果您有更多信息,请编辑您现有的问题 – jrturton