0

需要一些有关石英 2d 的帮助,这对我来说是全新的。

基本上我的应用程序需要跟随触摸,从中心开始多次绘制这条线。问题是它必须是动态的,并且线条必须均匀分布(有点像章鱼从中心开始)。我在android上的方式是我记住数组中的形状路径,而不是通过旋转坐标系多次绘制它,但我不知道如何在iOS上做到这一点。

我的旋转功能

- (void) rotateContext:(int)angle 
{


    CGContextTranslateCTM(UIGraphicsGetCurrentContext(), self.center.x, self.center.y);
    CGContextRotateCTM(UIGraphicsGetCurrentContext(), radians(angle));
    CGContextTranslateCTM(UIGraphicsGetCurrentContext(), -self.center.x, -self.center.y);


}

仅当我尝试在 drawRect() 中执行此操作时它才有效,并且它会旋转所有路径。

你能建议我一个解决问题的好方法吗?

谢谢

4

1 回答 1

0

这可以引导您找到解决方案:( 也许它甚至可以编译)

/* setup the context */
UIBezierPath *bpath = [UIBezierPath bezierPath];
UIBezierPath *subpath =
[UIBezierPath bezierPathWithOvalInRect:<#some rect#>];
[bpath appendPath:subpath];
/* add more stuff to the path as you wish */

bezierPath.lineWidth = 2;     
/* draw the same path rotated multiple times */
for(NSInteger i = 0; i < 4; i++) {
    [bpath applyTransform:CGAffineTransformMakeRotation(M_PI_2 * i)];
    [bpath stroke];
}
/* teardown the context */

旋转贝塞尔曲线很棘手,您需要根据您期望的结果应用更复杂的转换。

这些贝塞尔路径对象可以存储在数组或您需要的任何内容中。

于 2013-05-28T20:30:29.163 回答