我正在尝试实现一个自定义的Uiview,这基本上是馅饼菜单(类似于蛋糕分为切片)。

为此,我试图从中心绘制一个圆圈和一系列线,就像图轮中的光线一样。

我已经成功地绘制了圆圈,现在我想绘制将圆圈划分为切片的线。

这就是我到目前为止所拥有的:

-(void)drawRect:(CGRect)rect{

     [[UIColor blackColor] setStroke];
     CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGFloat minDim = (rect.size.width < rect.size.height) ? rect.size.width : rect.size.height;

    CGRect circleRect =  CGRectMake(0, rect.size.height/2-minDim/2, minDim, minDim); 

    CGContextAddEllipseInRect(ctx, circleRect);
    CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor yellowColor] CGColor]));
    CGContextFillPath(ctx);

    CGPoint start = CGPointMake(0, rect.size.height/2);
    CGPoint end = CGPointMake(rect.size.width, rect.size.height/2);

    for (int i = 0; i < MaxSlices(6); i++){

        CGFloat degrees = 1.0*i*(180/MaxSlices(6));
        CGAffineTransform rot = CGAffineTransformMakeRotation(degreesToRadians(degrees));

        UIBezierPath *path = [self pathFrom:start to:end];
        [path applyTransform:rot];

    }
 }   

- (UIBezierPath *) pathFrom:(CGPoint) start to:(CGPoint) end{

    UIBezierPath*    aPath = [UIBezierPath bezierPath];
    aPath.lineWidth = 5;
    [aPath moveToPoint:start];
    [aPath addLineToPoint:end];
    [aPath closePath];
    [aPath stroke];
    return aPath;
}

问题在于,路径上的应用似乎没有任何作用。正确绘制的第一个路径是正确绘制的,以下路径不受旋转影响。基本上我看到的只是一条路。在这里检查屏幕截图 http://img837.imageshack.us/img837/9757/iossimulatorscreenshotf.png

谢谢您的帮助!

有帮助吗?

解决方案

您正在画路径(有 stroke)在您改造它之前。路径只是数学表示。这不是“屏幕上”的行。您无法通过修改有关它的数据来移动已经绘制的内容。

只需移动即可 [aPath stroke] 在......之外 pathFrom:to: 然后把它放在 applyTransform:.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top