在iphone中无动画缩放多边形

时间:2013-08-22 12:56:49

标签: ios cgpath cashapelayer

我使用CGPath绘制了多边形(六边形),绘制后添加到CAShapeLayer。现在当我点击多边形时,那时我想要改变那个没有动画的多边形的比例(更大)。 这是代码:

//pointsForPolygonInRect will generate points for polygon
NSArray *arrayOfCoordinates = [self pointsForPolygonInRect:CGRectMake(0, 0, 400, 400)            
                                             numberOfSides:6];
NSEnumerator *enumerator = [arrayOfCoordinates objectEnumerator];
CGMutablePathRef path = CGPathCreateMutable();
CGPoint firstCoordinatePoint = [[enumerator nextObject] CGPointValue];
CGPathMoveToPoint(path, NULL, firstCoordinatePoint.x, firstCoordinatePoint.y);

CGPoint nextCoordinatePoint;
NSValue *coordinate;
while (coordinate = [enumerator nextObject]) {
    nextCoordinatePoint = [coordinate CGPointValue];
    CGPathAddLineToPoint(path, NULL, nextCoordinatePoint.x, nextCoordinatePoint.y);
}
CAShapeLayer* layer = [CAShapeLayer layer];

layer.frame = CGPathGetPathBoundingBox(path);

layer.path = path;
CGPathRelease(path);
layer.fillColor = [UIColor redColor].CGColor;
[self.layer addSublayer:layer];

请帮助我。谢谢你。

0 个答案:

没有答案