【问题标题】:How to tag imageview like Facebook instagram. in ios ( mark coordinates on imageview)如何像 Facebook instagram 一样标记 imageview。在 ios 中(在 imageview 上标记坐标)
【发布时间】:2015-09-22 05:38:33
【问题描述】:

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

【问题讨论】:

    标签: ios uiimageview tags


    【解决方案1】:

    您在情节提要(或代码)中创建 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 上绘制一个正方形。现在您可以将point 保存在您的数据库中,并在需要显示图像时绘制方形标签。

    希望对你有所帮助。

    【讨论】:

    • 我们如何确保保存在数据库中的点适用于任何显示器尺寸(iPhone 6 或 6 plus 或 SE)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2014-08-21
    • 2016-01-09
    相关资源
    最近更新 更多