我已经使用核心图形绘制了多边形。但是我无法调整多边形的大小。我用UIBezierPath绘制了多边形。这是我的代码

CGPoint gestureStartPoint,currentPosition;
- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        currentPath = [[UIBezierPath alloc]init];
        currentPath.lineWidth=1;
        xx1 = 30;
        yy1 = 30;
        xx = 30;
        yy = 30;
        CGPoint gestureStartPoint,currentPosition;
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    if(drawColor==nil){
        [[UIColor redColor]setStroke];
        [currentPath stroke];
    }
    else {
        [drawColor setStroke];
        [currentPath stroke];
    }
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        gestureStartPoint = [touch locationInView:self];
        currentPosition.x = xx;
        currentPosition.y = yy;
        xx = gestureStartPoint.x;
        yy = gestureStartPoint.y;
        [currentPath moveToPoint:(currentPosition)];
        [currentPath addLineToPoint:(gestureStartPoint)];
        [self setNeedsDisplay];
}


这是示例resizable Polygon的链接。如何用这种可调整大小的属性绘制多边形?我不知道从哪里开始制作可调整大小的多边形。

最佳答案

这比简单地调用一些CoreGraphics魔术要复杂得多。

为了简单地复制链接到的站点上的逻辑,我将首先解决问题:

可以识别两种类型的手势:轻击和轻按并拖动。

点击应将x,y(点)添加到要存储并重绘的点的列表中。

点击保持拖动应使用用户点击的x,y位置来确定最接近的顶点-并且您可能还应该进行一些最大距离检查。一旦确定了用户“拖动”哪个顶点,就可以在列表中操作该点并重新绘制。

关于iphone - 如何在iPhone中绘制可调整大小的多边形?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8242285/

10-14 21:45
查看更多