gpt4 book ai didi

ios - 如何像 Facebook instagram 一样标记 imageview。在 ios 中(在 imageview 上标记坐标)

转载 作者:行者123 更新时间:2023-11-29 01:38:28 27 4
gpt4 key购买 nike

我想在 imageview 上标记一些东西并且必须存储在数据库中,当我从数据库中检索它时,我必须在 imageview 上显示相同的坐标 ta。

最佳答案

您在 Storyboard(或代码)中创建一个 UIImageView,并在您的 viewController 中创建 fowling 属性:

@property (strong, nonatomic) UITapGestureRecognizer *tapGesture;

接下来,在viewDidLoad中初始化tapGesture:

self.tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGesture:)];

self.tapGesture.delegate = self;

[self.view addGestureRecognizer:self.tapGesture];

接下来,为点击创建处理程序:

- (void)handleSingleTapGesture:(UITapGestureRecognizer *)tapGestureRecognizer {

CGPoint point = [tapGestureRecognizer locationInView:self.imageView];
float squareSize = 10;

UIGraphicsBeginImageContextWithOptions(self.imageView.frame.size, YES, 0);

[self.imageView.image drawInRect:CGRectMake(0, 0, self.imageView.frame.size.width, self.imageView.frame.size.height)];

CGContextMoveToPoint(UIGraphicsGetCurrentContext(), point.x-squareSize, point.y - squareSize);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), point.x+squareSize, point.y-squareSize);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), point.x+squareSize, point.y+squareSize);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), point.x-squareSize, point.y+squareSize);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), point.x-squareSize, point.y-squareSize);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 1);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0,0,0,1);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);

CGContextStrokePath(UIGraphicsGetCurrentContext());
self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
[self.imageView setAlpha:1.0];
UIGraphicsEndImageContext();

}

此代码在 imageView 上绘制了一个正方形。现在您可以将保存在数据库中,并在需要显示图像时绘制方形标签。

希望这对您有帮助。

关于ios - 如何像 Facebook instagram 一样标记 imageview。在 ios 中(在 imageview 上标记坐标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32709138/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com