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