0
有没有办法让用户在iOS中使用圆形(透明圆)绘制三角形。我在考虑在圆圈中设置三个相等的点来创建三角形,并且在三角形构建时拉伸圆圈。也许使用bezierPathWithArcCenter或bezierPathWithOvalInRect。任何人都做过这个?使用圆绘制三角形
有没有办法让用户在iOS中使用圆形(透明圆)绘制三角形。我在考虑在圆圈中设置三个相等的点来创建三角形,并且在三角形构建时拉伸圆圈。也许使用bezierPathWithArcCenter或bezierPathWithOvalInRect。任何人都做过这个?使用圆绘制三角形
假设您已经拥有手势识别器或其他系统来捕捉用户触摸的位置,则绘制本身很简单。
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw circle
CGFloat derivedRadius = self.radius * self.scale;
CGPoint origin = CGPointMake(self.center.x - derivedRadius, self.center.y - derivedRadius);
CGContextAddEllipseInRect(context, CGRectMake(origin.x, origin.y, derivedRadius * 2, derivedRadius * 2));
// Draw triangle
CGFloat t1 = self.rotation;
CGFloat t2 = self.rotation + ((2 * M_PI)/3);
CGFloat t3 = self.rotation + ((4 * M_PI)/3);
CGPoint p1 = CGPointMake(self.center.x + cosf(t1) * derivedRadius, self.center.y + sinf(t1) * derivedRadius);
CGPoint p2 = CGPointMake(self.center.x + cosf(t2) * derivedRadius, self.center.y + sinf(t2) * derivedRadius);
CGPoint p3 = CGPointMake(self.center.x + cosf(t3) * derivedRadius, self.center.y + sinf(t3) * derivedRadius);
CGPoint endpoints[] = { p1, p2, p3, p1 };
CGContextAddLines(context, endpoints, 4);
CGContextStrokePath(context);
凡self.radius
,self.scale
,self.center
和self.rotation
是捕获用户的手势的结果属性。旋转应以弧度表示。
你想绘制一个三角形给定它的incircle? – 2012-11-20 21:12:57
有一个圆和里面的三角形。 – JProg