我想在 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
}
}