从UIImageView中删除Line

时间:2015-01-15 06:49:19

标签: ios objective-c uiimageview

我在UIImageView上画了一条直线。现在我想删除该绘制的行,如果用户点击它。这是我在Image上画一条线的代码。

- (void)handleLongPressGestures:(UILongPressGestureRecognizer *)sender
{
            if (sender.state == UIGestureRecognizerStateEnded)
            {

       CGPoint  location=[sender locationInView:imageView];
       CGPoint contextLocation = CGPointMake(location.x*imageView.image.size.width/imageView.frame.size.width, location.y*imageView.image.size.height/imageView.frame.size.height);
       UIColor * linearcolor=[UIColor blueColor];
       CGSize imagesize=imageView.image.size;
       UIGraphicsBeginImageContext(imageView.image.size);
       [imageView.image drawAtPoint:CGPointMake(0, 0)];
       CGContextRef context=UIGraphicsGetCurrentContext();
       CGContextSetLineWidth(context, 2.0);
       CGPoint location2=CGPointMake(300, 400);
       CGContextBeginPath(context);
       CGContextMoveToPoint(context, contextLocation.x, contextLocation.y);
       CGContextAddLineToPoint(context, location2.x, location2.y);
       CGContextAddQuadCurveToPoint(context, contextLocation.x, contextLocation.y, location2.x, location2.y);
       CGContextSetLineCap(context, kCGLineCapRound);
       if([removeLine  isEqualToString:@"true"])
       {            
         CGContextClearRect (context, CGRectMake(location2.x, location2.y, contextLocation.x, contextLocation.y));
           CGContextFlush(context); 
      }

       CGContextSetStrokeColorWithColor(context,[linearcolor CGColor]);
       CGContextStrokePath(context); 
       UIImage * newImage=UIGraphicsGetImageFromCurrentImageContext();
       UIGraphicsEndImageContext();
       removeLine=@"true";
       imageView.image=newImage;

    }
}

0 个答案:

没有答案