2015-09-22 37 views

回答

1

你创建你的故事板一个UIImageView(或者代码),并在您viewController创建打鸟属性:

@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保存到数据库中,并且在需要显示图像时可以绘制方形标记。

我希望这对你有所帮助。

+0

我们如何确保保存在我们的数据库中的点可以在任何显示尺寸(iPhone 6或6 plus或SE)上工作, – JayVDiyk