我想在iOS中使用具有以下概念的图像编辑应用程序创建应用程序 。当我点击图像上的位置时,相关位置应该缩放,如果我在其上绘制一个圆圈,它将在关闭缩放位置时保存到准确位置
。当我点击图像时,我使用CAShapelayer做了一些事情,将通过以下代码以编程方式绘制一个圆圈
。现在当我点击图像时工作将完美地画出一个圆圈
。但我希望,当我点击图像时,它会创建一个小的圆形图像视图,并填充点击的图像(缩放图像)
。当我点击该缩放的图像视图时,需要创建一个圆圈并关闭缩放视图,并且还需要在正常图像上显示圆圈
。有图书馆吗?我希望有人会帮忙做到这一点。
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touch_point = [touch locationInView:self.view];
if ([imgVw pointInside:touch_point withEvent:event])
{
NSLog(@"point inside imageview");
CGPoint point = [touch locationInView:self.view];
NSLog(@"X location: %f", point.x);
NSLog(@"Y Location: %f",point.y);
CAShapeLayer *circleLayer = [CAShapeLayer layer];
// Give the layer the same bounds as your image view
[circleLayer setBounds:CGRectMake(0.0f, 0.0f, [imgVw bounds].size.width,
[imgVw bounds].size.height)];
// Position the circle anywhere you like, but this will center it
// In the parent layer, which will be your image view's root layer
[circleLayer setPosition:CGPointMake([imgVw bounds].size.width/2.0f,
[imgVw bounds].size.height/2.0f)];
// Create a circle path.
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:
CGRectMake(point.x, point.y, 10.0f, 10.0f)];
// Set the path on the layer
[circleLayer setPath:[path CGPath]];
// Set the stroke color
[circleLayer setStrokeColor:[[UIColor redColor] CGColor]];
// Set the stroke line width
[circleLayer setLineWidth:2.0f];
[layerArray addObject:circleLayer]; // will push all layer in to array it will help to re edit like undo operation
[[imgVw layer] addSublayer:circleLayer]; //will add a circle on image
}
}